Skip to content
Latchkey

du: Usage, Options & Common CI Errors

du measures how much disk space files and directories consume.

du is the follow-up to df: once you know a disk is full, du tells you which directories are responsible. The summarize and depth flags keep its output usable on big trees.

What it does

du walks directories and reports the disk space used by each, recursively. It measures actual blocks consumed (with --apparent-size for logical bytes), which is why its totals can differ from file sizes.

Common usage

Terminal
du -sh ./node_modules          # one summarized total
du -h --max-depth=1 . | sort -h  # biggest top-level dirs
du -sh * | sort -h               # rank items in cwd
du -ch *.log | tail -1           # grand total of logs
du -sh /var/lib/docker

Options

FlagWhat it does
-hHuman-readable sizes
-s / --summarizeOne total per argument
-cPrint a grand total
-d N / --max-depth=NLimit reporting depth
--apparent-sizeLogical bytes, not blocks used

Common errors in CI

du can be slow on huge trees - bound it with -d 1 or -s rather than printing every file. "du: cannot access "X": Permission denied" lines are warnings on dirs you cannot read (filter with 2>/dev/null) and du still totals the rest. Note BSD/macOS du reports in 512-byte blocks by default - pass -h or set BLOCKSIZE. To find the culprit fast: du -h -d1 / 2>/dev/null | sort -h.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →