Sample output
14G .
4.2G ./node_modules
3.8G ./.git
2.1G ./dist
1.4G ./uploads
The current directory totals 14 G, and almost a third of it is node_modules. The rest is the git history and build output.
When you would reach for it
When a disk-full warning fires, when a Docker image bloats past its budget, or when you just want to know where the space went before reaching for a GUI tool.
Gotchas
- On macOS,
sort -hrequires GNU coreutils (brew install coreutils, then usegsort -hr). The BSDsortdoes not understand human-readable suffixes. The command still works, but you get an alphabetical sort of the size column. - Symlinks are not followed by default, so a symlink to a large directory will not inflate the count.
Variants
$ du -h -d1 . | sort -hr | head -10
GNU/Linux, works as-is
$ du -h -d1 . | gsort -hr | head -10
macOS with GNU coreutils installed