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
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/dockerOptions
| Flag | What it does |
|---|---|
| -h | Human-readable sizes |
| -s / --summarize | One total per argument |
| -c | Print a grand total |
| -d N / --max-depth=N | Limit reporting depth |
| --apparent-size | Logical 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.