๐ŸŽ New User? Get 20% off your first purchase with code NEWUSER20 ยท โšก Instant download ยท ๐Ÿ”’ Secure checkout Register Now โ†’
Menu

Categories

๐Ÿ’ก Disk & Storage August 22, 2026 9

Linux Command: du

Estimate file and directory space usage

Terminal โ€” Disk & Storage
Command
$ du -sh /home/* | sort -rh | head -10
Output
50G\t/home/developer\n12G\t/home/admin\n2G\t/home/guest

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 -10

Output: 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 | head

Output: 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 โ†’

Share this tip