Estimate disk usage of files and directories.
low risk
du walks the directory tree summing file sizes. -s gives a total for each argument. --max-depth limits recursion depth. Piping to `sort -rh` reveals the biggest disk consumers — essential for tracking down space hogs.
| Flag | Meaning |
|---|---|
-h --human-readable | Print sizes in human-readable format |
-s --summarize | Display only a total for each argument |
-a --all | Include all files, not just directories |
--max-depth | Limit directory recursion depth |
--exclude | Exclude files matching a pattern |
du -sh /var/log/*Show size of each item in /var/log · explain & risk-check →du -h --max-depth=2 / | sort -rh | head -20Find top 20 largest directories from root · explain & risk-check →du -sh --exclude='.git' .Get total size of current directory excluding .git · explain & risk-check →Install `ncdu` for an interactive disk usage explorer: `sudo apt install ncdu && ncdu /`
Reference text is hand-written and may be incomplete — check man du for your version. Test destructive commands on a non-production system first.