Before checking filesystem free space, you may first want to know how much space a particular directory uses. The du command estimates the space used by that directory and its contents.
I’ll explain what du measures and show how to request a total or inspect another directory level.
TL;DR
Use the readable-units option with a one-level depth limit to see child totals.
- The human-readable option adds unit labels such as K, M and G.
- The summary option prints one total per path, while a one-level depth setting shows immediate children.
- Use df with readable units when you need capacity and free space for mounted filesystems.
What the du command measures
du estimates space used by the paths you give it. Without a path, GNU du starts at the current directory. Its default scale is 1024 bytes per displayed unit, though environment settings can change it, so I request readable units when comparing directories.
The df guide covers mounted-filesystem capacity and available space, a different question from this directory scan.
How to use the du command in Linux step by step
Use a shallow breakdown to find large children, then choose a total, deeper view or filter.
Step 1: Show each directory’s usage
Pass a directory to du and limit the report to its first level. GNU du numbers the starting path as depth zero, so depth one includes its immediate children and the starting directory’s aggregate.
#!/usr/bin/env bash
set -eu
mkdir -p du-example/projects du-example/photos
printf 'sample notes\n' > du-example/notes.txt
printf 'source file\n' > du-example/projects/app.py
printf 'image placeholder\n' > du-example/photos/photo.txt
du -h --max-depth=1 du-example
Save this source as du_example.sh and run it with bash du_example.sh. I ran the same file against its sample tree. The exact output was:
8.0K du-example/projects
8.0K du-example/photos
24K du-example

The first column is estimated space, the second the path. The final row includes both children.
Step 2: Choose a total or a deeper listing
Use -sh for one readable total for each named path. Use depth two or more when the first-level row is still too broad and you need to see another directory layer.
du -sh du-example
du -h --max-depth=2 du-example
du -ch du-example
The first form gives one total, the second shows two levels, and the third adds a grand total. Without a depth limit, output can be long.
Step 3: Find the largest paths
Use GNU sort’s human-readable mode to compare du’s size suffixes, with reverse order to put larger entries first.
du -h --max-depth=1 DIRECTORY | sort -hr
Read child rows separately from the parent aggregate. Keep the depth limited on large trees.
Step 4: Exclude matching entries
The exclusion option skips matching files or directories during traversal. It accepts shell wildcards.
du -h --max-depth=1 --exclude='*.cache' DIRECTORY
Single quotes pass the wildcard to du. The command filters names ending in .cache without changing them.
du command limits and useful next steps
Use these boundaries when a directory total does not answer the storage question.
| Situation | What to know | Next check |
|---|---|---|
| Need logical byte length | The apparent-size option reports logical bytes, which can differ from allocated usage. | Compare the standard report with the apparent-size report. |
| Symbolic links are present | GNU du does not follow symbolic links by default. | Follow links only when you intend to count their targets. |
| Need to avoid crossing mounts | The one-filesystem option stays on the filesystem containing the starting path. | Compare with Linux filesystem paths and mounts. |
| Need filesystem free space | du walks directory entries, while filesystem counters can include allocations beyond names visible in the walk. | Run df -h. |
du -h --apparent-size du-example
du -h -L du-example
du -h -x du-example
Apparent size follows logical lengths, so sparse files can look larger than allocated blocks. GNU du skips symbolic links unless asked to follow them. The one-filesystem option avoids crossing mounts.
A deleted file can remain allocated while a process holds it open, so df may exceed visible du totals. Use find to locate files by attributes.
Conclusion: choose the output that answers your question
Use path totals to locate large directories and filesystem counters for free capacity.
See the GNU Coreutils du manual for all options.
FAQ
These answers cover common questions about scope and output.
What does the du command do in Linux?
GNU du estimates space usage for files and directories by traversing the paths you provide. With no path, it starts at the current directory.
How do I show the size of each subdirectory?
Set a maximum depth of one and use the human-readable option with your chosen directory.
What is the difference between du and df?
du estimates usage for selected paths. df reports capacity and available space for mounted filesystems.
How can I get one total for a directory?
Use du -sh DIRECTORY for a summarized total in human-readable units.
