Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to use du to sort the output by filesize, but it doesn't looks like there's an option for that.

Can I pipe it into another command to handle the sorting?

share|improve this question
up vote 5 down vote accepted

Shorter, and more succinct (and no Perl ;) ):

du -sm | sort -nr
share|improve this answer
Gnu sort has an option -h to sort human-readable SI numbers, with 4K being smaller than 1M. It's an option when -m/-g/-k don't work well. – Daniel Beck Nov 28 '12 at 19:57
Nice, +1, you don't need the * though, du will run on the current directory by default. – terdon Nov 29 '12 at 13:26

Try this:

alias duf='du -sk * | sort -n | perl -ne '\''($s,$f)=split(m{\t});for (qw(K M G)) {if($s<1024) {printf("%.1f",$s);print "$_\t$f"; last};$s=$s/1024}'\'
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.