Sorting Directories On Size, Human Readable

So far i have this:

du -h –max-depth=1 | grep ‘[0-9]K’ | sort -n ; du -h –max-depth=1 | grep ‘[0-9]M’ | sort -n | du -h –max-depth=1 | grep ‘[0-9]G’ | sort -n

To include regular files in this sorting just use du -ah instead…

Edit: A far better version as pointed by deice is:


du -s * | sort -n | cut -f 2- | while read a; do du -hs $a; done

Technorati Tags: , , , ,

~ by princ3 on April 28, 2007.

2 Responses to “Sorting Directories On Size, Human Readable”

  1. That wouldn’t work with eg. 1.2G would it ?

    My version is:

    du -s * | sort -n | cut -f 2- | while read a; do du -hs “$a”; done

    This seems to work okay, although it requires doing du twice, in principle. But this isn’t a major problem because due to caching the second run should be lightning fast.

  2. This works also for 1.2G, but your version is nicer :) thx.

Leave a Reply