← back to latest

Find out what is actually eating your disk

du -h -d1 . | sort -hr | head -10

anatomy

du
Disk usage. Walks the directory tree and sums up the size of every file it finds.
-h
Human-readable sizes: K, M, G rather than raw byte counts.
-d1
Depth 1. Only report totals for the immediate children, not every nested subdirectory.
.
Start from the current directory. Replace with any path.
sort -hr
Sort by human-readable numbers in reverse order, so the biggest directory is first.
head -10
Show only the top ten entries. Remove it to see everything.

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 -h requires GNU coreutils (brew install coreutils, then use gsort -hr). The BSD sort does 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

lineage

du dates back to Version 1 Unix at Bell Labs in 1971, making it one of the oldest commands still in daily use. Ken Thompson and Dennis Ritchie included it in the original system alongside ls and cat, because even on a PDP-11 with a few megabytes of disk, someone always needed to know where the space went. The command survived mostly unchanged through every major Unix lineage: BSD, System V, POSIX, and eventually GNU coreutils, which added the -h flag for human-readable output in the late 1990s. The -d (max depth) flag appeared in BSD and was adopted by GNU as --max-depth before the short form followed. Today every Unix-like system ships du, and the interface is close enough to Thompson's original that a 1971 script using du would still parse on a modern machine.