List directories ordered by size (with human-readable output)

Posted Almost 13 years ago. Visible to the public.

You know there is the du command to fetch the disk usage of a directory (“.” in this example). By default, output is sorted by directory name, not size:

du -h --max-depth=1 .
40K  ./a
2.3G ./b
3.1M ./c
500M ./d
2.8G .

To see which directories take up the most (or least) space you can order them by size like this (the -h switch does the magic of understanding humanized size formats):

du -h --max-depth=1 . | sort -h
40K  ./a
3.1M ./c
500M ./d
2.3G ./b
2.8G .

Note that you will need to wait for du to compute its whole output which then gets piped into sort.

Arne Hartherz
Last edit
About 9 years ago
Dominik Schöler
Keywords
linux, unix, bash, drive, hdd
License
Source code in this card is licensed under the MIT License.
Posted by Arne Hartherz to makandra dev (2011-06-08 08:24)