On 27/03/2026 09:58, Daniel wrote:
Hi,

I'd like to propose a small addition to du: a --sort=size flag that
automatically sorts output by size (descending) and limits depth to 1.

Motivation

The most common real-world use of du is finding what's consuming disk space
in a directory. The typical workflow is:

du -h --max-depth=1 /home | sort -rh

This requires piping to sort, which breaks --total, loses context when
combined with other flags, and is non-obvious for new users.

Proposed behavior

du -h --sort=size /home

- Implies --max-depth=1
- Sorts output by size, descending
- Compatible with -h, --time, --total
- If entries exceed 10,000, truncates with a message: ... and N smaller
entries omitted

Scope

Implementation would be ~100 LOC in du.c, reusing existing print_size() and
related helpers. I've searched the mailing list archives and Savannah
tracker and found no existing proposal for this.

I considered a short option alias but -s and -S are already taken. Open to
suggestions.

Before writing the patch, I wanted to check if this would be welcome and if
there are any design concerns I should consider.

Well it was discussed previously and not accepted:
https://www.gnu.org/software/coreutils/rejected_requests.html#du
sorting is hard to implement without various limitations
and GNU tools try to avoid such limitations.

You also may find something like this useful:
https://www.pixelbeat.org/scripts/dutop

cheers,
Padraig

Reply via email to