du

Estimate file and directory space usage.

Synopsis

du [options] [path]

When to Use It

Use du when a server or local workspace is running out of disk, when a build artifact suddenly becomes huge, or when you need a quick directory-by-directory breakdown before cleaning up logs, caches, containers, or uploads.

Core Options

-h

Human-readable sizes.

-s

Summary only.

--max-depth N

Limit recursion depth.

-a

Show files as well as directories.

-x

Stay on one filesystem.

Usage Examples

Directory Summary

Total size of a folder.

du -sh ./logs

Top-level Breakdown

Sizes of immediate subfolders.

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

Include Files

Show file sizes too.

du -ah ./data | sort -h | tail

Apparent Size

Inspect apparent size instead of allocated blocks.

du -sh --apparent-size ./backup.tar

Single Filesystem

Avoid crossing into mounted volumes.

du -xh --max-depth=1 /var

Common Mistakes

  • du reports allocated disk usage, not always the exact apparent file size, so sparse files can look smaller or larger than expected.
  • Running du without depth limits on a very large tree can be slow and noisy; add -s or --max-depth when you only need summaries.
  • If you forget -x, the command may cross filesystem boundaries and mix results from mounted volumes.

Related

Built for builders.