How to get the summarized sizes of directories and their subdirectories?
This does what you're looking for:
du -sh /*
What this means:
-s
to give only the total for each command line argument.-h
for human-readable suffixes likeM
for megabytes andG
for gigabytes (optional)./*
simply expands to all directories (and files) in/
.Note: dotfiles are not included; run
shopt -s dotglob
to include those too.
Also useful is sorting by size:
du -sh /* | sort -h
Here:
-h
ensures thatsort
interprets the human-readable suffixes correctly.
I often need to find the biggest directories, so to get a sorted list containing the 20 biggest dirs I do this:
du -m /some/path | sort -nr | head -n 20
In this case the sizes will be reported in megabytes.
I like to use Ncdu for that, you can use the cursor to navigate and drill down through the directory structure it works really well.