Skip to main content

du Cheatsheet

By Dejan Panovski Updated on Download PDF

Quick reference for the du command: check directory sizes, human-readable output, depth limits, sorting by size, exclusions, and apparent size.

du reports the disk space used by files and directories. This cheatsheet covers the most common options, depth and exclusion filters, sorting recipes, and the difference between allocated and apparent size.

Basic Usage

Common ways to check directory and file sizes.

CommandDescription
duShow disk usage of the current directory and its subdirectories
du fileShow disk usage of a single file
du dir1 dir2Show disk usage for multiple paths
du -h dirHuman-readable sizes (K, M, G)
du -sh dirShow only the total size of a directory
du -sh *Show the size of every item in the current directory
sudo du -sh /varRun with sudo to read root-owned paths

Size Formats

Control how sizes are printed.

OptionDescription
-hHuman-readable, powers of 1024 (K, M, G)
-HHuman-readable, powers of 1000 (SI units)
-kDisplay sizes in 1K blocks (default on most systems)
-mDisplay sizes in 1M blocks
-BGDisplay sizes in 1G blocks
-B SIZEUse SIZE-byte blocks, for example -BM or -B512
-bEquivalent to --apparent-size --block-size=1

Summary and Totals

Reduce noise or add a grand total row.

CommandDescription
du -s dirShow only the total for the given directory
du -sh dirTotal in human-readable format
du -c dir1 dir2Add a total line at the bottom
du -csh /var/log /var/libHuman-readable totals plus a combined grand total
du -a dirInclude every file in the listing, not just directories

Depth Control

Limit how deep du descends into the directory tree.

CommandDescription
du -h --max-depth=1 dirShow only the first level of subdirectories
du -h --max-depth=2 dirShow two levels deep
du -h -d 1 dirShort form of --max-depth=1
du -h --max-depth=0 dirShow only the directory total (same as -s)

Excluding Files

Skip paths or patterns from the report.

OptionDescription
--exclude=PATTERNSkip files and directories matching the shell pattern
--exclude-from=FILERead exclude patterns from a file
-xStay on the same filesystem (skip mounted ones)

Examples:

CommandDescription
du -sh --exclude="*.log" /varExclude .log files from the total
du -sh --exclude=node_modules ~/projectsSkip 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.

CommandDescription
du -h dir | sort -rhSort entries by size, largest first
du -h dir | sort -rh | head -10List the 10 largest items
du -h --max-depth=1 / | sort -rh | head -20Largest top-level directories under /
du -ah dir | sort -rh | head -10Largest individual files and directories
du -sh */ | sort -rhSort current directory’s children by size

Apparent vs Disk Usage

du reports allocated blocks by default. Use these flags to see actual byte counts.

OptionDescription
--apparent-sizeShow how many bytes the file contains, not how much it occupies on disk
-bApparent size in bytes (shorthand for --apparent-size --block-size=1)

Examples:

CommandDescription
du -sh --apparent-size /var/logApparent size of /var/log
du -sb fileExact byte count of a file

Counting and Time

Less common but useful options.

OptionDescription
-LFollow all symbolic links
-PNever follow symbolic links (default)
-lCount sizes many times if hard linked
--timeShow last modification time of the file or directory
--time=atimeShow the access time instead of modification time
-0Use a NUL character as the line separator (for piping into xargs -0)

Use these references for deeper disk usage workflows.

GuideDescription
du Command in LinuxFull du guide with practical examples
How to Get the Size of a File or DirectoryFocused walkthrough for sizing files and directories
How to Check Disk Space in Linux Using dfFilesystem-level disk space reporting
Find Large Files in LinuxLocate the biggest files across a tree