🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

du Command

Beginner Disk & Storage man(1)

Estimate file and directory space usage

👁 10 views 📅 Updated: Mar 15, 2026
SYNTAX
du [OPTION]... [FILE]...

What Does du Do?

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).

Options & Flags

OptionDescriptionExample
-h Human-readable sizes du -h /var/log/
-s Show only total for each argument du -sh /home/*
-a Show all files, not just directories du -ah /var/log/
-c Show grand total du -shc /var/log/ /var/www/
--max-depth Limit directory depth du -h --max-depth=1 /
-x Stay on same filesystem du -shx /
--exclude Exclude pattern du -sh --exclude='*.log' /var/

Practical Examples

#1 Find largest directories

Shows the 10 largest home directories.
$ du -sh /home/* | sort -rh | head -10
Output: 50G\t/home/developer\n12G\t/home/admin\n2G\t/home/guest

#2 Directory summary

Shows total size for each specified directory.
$ du -sh /var/log/ /var/www/ /tmp/
Output: 2.5G\t/var/log/\n15G\t/var/www/\n500M\t/tmp/

#3 First level breakdown

Shows space usage for top-level directories.
$ du -h --max-depth=1 / 2>/dev/null | sort -rh | head
Output: 50G\t/var\n20G\t/home\n5G\t/usr

#4 Find large files

Finds the 20 largest files and directories under /var.
$ du -ah /var/ | sort -rh | head -20

#5 Current directory usage

Shows total size of the current directory.
$ du -sh .
Output: 3.2G\t.

#6 Exclude patterns

Shows directory size excluding common large directories.
$ du -sh --exclude='node_modules' --exclude='.git' ./

Tips & Best Practices

du -sh * | sort -rh: This one-liner quickly shows the largest items in the current directory, sorted by size. Essential for disk cleanup.
du vs ls -l: du shows actual disk usage (allocated blocks). ls -l shows file size. A sparse file may show 1GB in ls but 0 in du.
Can be slow: du traverses all files. On large filesystems, du / can take minutes. Use ncdu for interactive, cached exploration.

Frequently Asked Questions

How do I find what is using disk space?
du -sh /path/* | sort -rh | head shows the largest items. Start at / and drill down into the largest directories.
How do I check directory size?
du -sh /path/to/directory shows the total size. Without -s, it shows every subdirectory.
What is the difference between du and df?
du shows directory/file sizes (what uses space). df shows filesystem usage (how full the disk is).

Master Linux with Professional eBooks

Curated IT eBooks covering Linux, DevOps, Cloud, and more

Browse Books →