Cheatsheet: du

Last updated 2026-09-18

Basic usage

Show disk usage for directories below the current directory in block-size units.

du

Show sizes in human-readable units such as K, M, and G.

du -h

Summarize the total size of one directory.

du -sh public

Summarize each item directly inside a directory.

du -sh public/*

Show a grand total after listing individual arguments.

du -ch public/*

Depth and scope

Limit output to the current directory and one level of children.

du -h -d 1 .

GNU equivalent for limiting output depth.

du -h --max-depth=1 .

Show apparent file size instead of allocated disk blocks, useful for sparse files.

du -sh --apparent-size disk-image.raw

Stay on one filesystem and do not cross mounted filesystems.

du -xh /

Count hard-linked files every time they are encountered instead of once.

du -hl .

Finding large items

Sort files and directories by size, smallest first.

du -s public/* | sort -n

Sort by size, largest first.

du -s public/* | sort -nr

Sort human-readable sizes, largest first.

du -sh public/* | sort -hr

Show the ten largest items in the current directory.

du -sh ./* | sort -hr | head -n 10

Show only entries at or above a threshold size with GNU du.

du -h --threshold=100M .

Show entries at or below a threshold size with GNU du.

du -h --threshold=-1M .

Excluding paths

Exclude a directory name pattern such as node_modules.

du -h --exclude='node_modules' .

Exclude multiple glob patterns using repeated --exclude options.

du -h --exclude='node_modules' --exclude='.git' .

Read exclude patterns from a file with GNU du.

du -h --exclude-from=.duignore .

--max-depth reference (GNU coreutils)

Semantics: --max-depth=N prints a total for every directory N or fewer levels below each argument, and hides deeper subdirectory lines. Files are only shown at all when -a/--all is also given; without -a, du only ever lists directory totals, and --max-depth simply limits how many directory levels are shown.

du -h --max-depth=1 .   # totals for . and its immediate children only

-d N is the short-option alias for --max-depth=N added by GNU coreutils; they are interchangeable.

du -h -d 1 .
du -h --max-depth=1 .   # identical result

--max-depth=0 is equivalent to -s/--summarize: only the grand total for each argument is printed, with no subdirectory detail.

du -sh public
du -h --max-depth=0 public   # identical result

Depth is measured relative to each argument you pass, not your current working directory — pointing --max-depth=1 at a parent path surfaces that path's own children, not yours.

du -h --max-depth=1 /var   # depth 1 relative to /var, not to .

--max-depth is a GNU extension (no POSIX standard, and BSD/macOS du lacks it, though BSD's -d N option is comparable). Check your platform's du before relying on GNU-only flags in portable scripts.

# GNU/Linux
du -h --max-depth=1 .
# BSD/macOS: no --max-depth, but -d N works the same way
du -h -d 1 .

FAQ