Show N biggest directories in linux bash

du (disk usage) utility in linux bash summarizes disk usage of each directory or file. By default, it outputs only directories. Just enter some dir and type

$ du ./

But if ./ has many subdirectories, output will be too long. And it is unsorted. The stated in the title task can be achieved by piping.

Sort output by size

Cut the first line, it is size of the ./ dir as sum of other sizes Use “—human-readable” in du or divide by 1024 to get kbytes, mbytes, etc. I divide by 1000 to get results close to nautilus ones.

The resulting command:

$ du -b --max-depth=1 | sort -nr | sed -n ''2,4p'' | awk ''{print $1/1000^3" Gb\t" $2}''