Disks and file system

Command du

Estimate the size of files and directories

Linux · Bash examples · commands run on the selected server

When to use du

Use du to locate disk consumption inside a directory tree. Start at the relevant application or data path rather than scanning the whole server, and distinguish allocated space from apparent file length.

Syntax

du [PARAMETERS] [PATH...]

Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.

Common options and arguments

-h
Show human-readable sizes.
-s
Only the total for each argument.
--max-depth=N
Limit output depth to GNU du.

Usage examples

Estimate project size

du -sh ./project

A single total summarizes the project's allocated disk usage.

Show the size of first level directories

du -h --max-depth=1 ./project

Per-directory totals expose which immediate subdirectories account for space.

Show apparent file sizes

du -sh --apparent-size ./project

Apparent length is measured instead of allocated blocks, which matters for sparse files.

Notes and limitations

  • The usual du evaluates occupied blocks; sparse files and links affect the result.
  • Even with output limited, du can traverse the entire tree: for large directories, consider disk load.

Common questions and troubleshooting

Why is du slow on a large directory?

It must traverse entries and read metadata. Restrict the scope and avoid repeatedly scanning large or remote trees.

Why does du miss some used space?

Unreadable paths, other mounts, snapshots or deleted files held open can fall outside the inspected tree. Compare its scope with df before interpreting differences.

Further help

Options vary by version and distribution. Check the installed documentation with this command: man du.