du
Overview
du estimates file space usage for files and directories. Essential for finding what is consuming disk after df shows a full filesystem.
Syntax
du [options] [file...]Common Options
| Option | Description |
|---|---|
-h |
Human-readable |
-s |
Summarize (total only) |
-a |
All files, not just dirs |
-c |
Grand total |
-d n / --max-depth=n |
Limit depth |
-x |
One filesystem |
-b |
Bytes |
--apparent-size |
Logical size vs allocated |
Examples with Explanations
Top-level breakdown
sudo du -h -d 1 /var 2>/dev/null | sort -hLargest children of current dir
du -h -d 1 . 2>/dev/null | sort -h | tailSummary of one tree
du -sh /var/logStay on one mount
du -xhd 1 /Apparent size vs disk usage
du -h file.sparse
du -h --apparent-size file.sparseCombine with find for huge files
find /var -xdev -type f -size +100M -exec du -h {} + 2>/dev/null | sort -h | tailNotes & Pitfalls
- Permission denied dirs understate totals without
sudo. - Hard links can double-count depending on options/version.
- Prefer
ncdufor interactive exploration when available.