du Cheatsheet
Basic Usage
Common ways to check directory and file sizes.
| Command | Description |
|---|---|
du
|
Show disk usage of the current directory and its subdirectories |
du file |
Show disk usage of a single file |
du dir1 dir2 |
Show disk usage for multiple paths |
du -h dir |
Human-readable sizes (K, M, G) |
du -sh dir |
Show only the total size of a directory |
du -sh * |
Show the size of every item in the current directory |
sudo du -sh /var |
Run with sudo to read root-owned paths |
Size Formats
Control how sizes are printed.
| Option | Description |
|---|---|
-h |
Human-readable, powers of 1024 (K, M, G) |
-H |
Human-readable, powers of 1000 (SI units) |
-k |
Display sizes in 1K blocks (default on most systems) |
-m |
Display sizes in 1M blocks |
-BG |
Display sizes in 1G blocks |
-B SIZE |
Use SIZE-byte blocks, for example -BM or -B512 |
-b |
Equivalent to --apparent-size --block-size=1 |
Summary and Totals
Reduce noise or add a grand total row.
| Command | Description |
|---|---|
du -s dir |
Show only the total for the given directory |
du -sh dir |
Total in human-readable format |
du -c dir1 dir2 |
Add a total line at the bottom |
du -csh /var/log /var/lib |
Human-readable totals plus a combined grand total |
du -a dir |
Include every file in the listing, not just directories |
Depth Control
Limit how deep du descends into the directory tree.
| Command | Description |
|---|---|
du -h --max-depth=1 dir |
Show only the first level of subdirectories |
du -h --max-depth=2 dir |
Show two levels deep |
du -h -d 1 dir |
Short form of --max-depth=1 |
du -h --max-depth=0 dir |
Show only the directory total (same as -s) |
Excluding Files
Skip paths or patterns from the report.
| Option | Description |
|---|---|
--exclude=PATTERN |
Skip files and directories matching the shell pattern |
--exclude-from=FILE |
Read exclude patterns from a file |
-x |
Stay on the same filesystem (skip mounted ones) |
Examples:
| Command | Description |
|---|---|
du -sh --exclude="*.log" /var |
Exclude .log files from the total |
du -sh --exclude=node_modules ~/projects |
Skip node_modules directories |
du -xsh / |
Total of the root filesystem only, ignoring mounts |
Sorting and Top N
Combine du with sort and head to find the largest items.
| Command | Description |
|---|---|
du -h dir | sort -rh |
Sort entries by size, largest first |
du -h dir | sort -rh | head -10 |
List the 10 largest items |
du -h --max-depth=1 / | sort -rh | head -20 |
Largest top-level directories under / |
du -ah dir | sort -rh | head -10 |
Largest individual files and directories |
du -sh */ | sort -rh |
Sort current directory’s children by size |
Apparent vs Disk Usage
du reports allocated blocks by default. Use these flags to see actual byte counts.
| Option | Description |
|---|---|
--apparent-size |
Show how many bytes the file contains, not how much it occupies on disk |
-b |
Apparent size in bytes (shorthand for --apparent-size --block-size=1) |
Examples:
| Command | Description |
|---|---|
du -sh --apparent-size /var/log |
Apparent size of /var/log |
du -sb file |
Exact byte count of a file |
Counting and Time
Less common but useful options.
| Option | Description |
|---|---|
-L |
Follow all symbolic links |
-P |
Never follow symbolic links (default) |
-l |
Count sizes many times if hard linked |
--time |
Show last modification time of the file or directory |
--time=atime |
Show the access time instead of modification time |
-0 |
Use a NUL character as the line separator (for piping into xargs -0) |
Related Guides
Use these references for deeper disk usage workflows.
| Guide | Description |
|---|---|
du Command in Linux
|
Full du guide with practical examples |
How to Get the Size of a File or Directory
|
Focused walkthrough for sizing files and directories |
How to Check Disk Space in Linux Using df
|
Filesystem-level disk space reporting |
Find Large Files in Linux
|
Locate the biggest files across a tree |





