Linux Command: du
Estimate file and directory space usage
du (disk usage) estimates file and directory space usage. Unlike df which shows filesystem-level usage, du shows how much space individual directories and files consume. du is the go-to tool for finding what is consuming disk space. Combined with sort, it quickly identifies the largest directories and files. The -s flag gives directory totals, and -h makes output human-readable. du reads actual disk usage (allocated blocks), not file sizes. A 1-byte file still uses one disk block (typically 4KB).
Syntax
du [OPTION]... [FILE]...Key Options
-hโ Human-readable sizes-sโ Show only total for each argument-aโ Show all files, not just directories-cโ Show grand total--max-depthโ Limit directory depth-xโ Stay on same filesystem
Examples
Find largest directories
du -sh /home/* | sort -rh | head -10Output: 50G\t/home/developer\n12G\t/home/admin\n2G\t/home/guest
Directory summary
du -sh /var/log/ /var/www/ /tmp/Output: 2.5G\t/var/log/\n15G\t/var/www/\n500M\t/tmp/
First level breakdown
du -h --max-depth=1 / 2>/dev/null | sort -rh | headOutput: 50G\t/var\n20G\t/home\n5G\t/usr
Pro Tips
- This one-liner quickly shows the largest items in the current directory, sorted by size. Essential for disk cleanup.
- du shows actual disk usage (allocated blocks). ls -l shows file size. A sparse file may show 1GB in ls but 0 in du.
- du traverses all files. On large filesystems, du / can take minutes. Use ncdu for interactive, cached exploration.
Learn more: Full du reference โ