Numerically sorted human readable disk usage

du -x --max-depth=1 | sort -n | awk '{ print $2 }' | xargs du -hx --max-depth=0
Provides numerically sorted human readable du output. I so wish there was just a du flag for this.
Sample Output
# du -x --max-depth=1 /var | sort -n | awk '{ print $2 }' | xargs du -hx --max-depth=0
0       /var/lock
128K    /var/run
4.0K    /var/crash
4.0K    /var/games
4.0K    /var/local
4.0K    /var/opt
4.0K    /var/tmp
8.0K    /var/mail
692K    /var/spool
7.2M    /var/backups
13M     /var/log
97M     /var/www
236M    /var/lib
539M    /var/cache
891M    /var

By: d34dh0r53
2010-02-18 19:46:47

6 Alternatives + Submit Alt

What Others Think

That's brilliant. And yeah, why isn't there an argument for this?
Xinerama · 650 weeks and 4 days ago
The most recent version of gnu coreutils contains sort with the -h option: ?-h? ?--human-numeric-sort? ?--sort=human-numeric? Sort numerically, as per the --numeric-sort option below, and in addition handle IEC or SI suffixes like MiB, MB etc (Block size). Note a mixture of IEC and SI suffixes is not supported and will be flagged as an error. Also the numbers must be abbreviated uniformly. I.E. values with different precisions like 6000K and 5M will be sorted incorrectly. --- I believe that this is in core-utils 8.4 -- the version in Ubuntu Karmic is core-utils 7.4, which does not support this.
bartonski · 650 weeks ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: