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
-hHuman-readable sizes.
-sSummary only.
--max-depth NLimit recursion depth.
-aShow files as well as directories.
-xStay on one filesystem.
Usage Examples
Directory Summary
Total size of a folder.
du -sh ./logsTop-level Breakdown
Sizes of immediate subfolders.
du -h --max-depth=1 ./Include Files
Show file sizes too.
du -ah ./data | sort -h | tailApparent Size
Inspect apparent size instead of allocated blocks.
du -sh --apparent-size ./backup.tarSingle Filesystem
Avoid crossing into mounted volumes.
du -xh --max-depth=1 /varCommon 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.