On this page
reference
2 min read
du
du — "disk usage" — reports how much space files and directories occupy. Where df tells you about a whole file system, du tells you where the space has actually gone.
du [options] [file...]
$ du -sh /home/jack/projects
4.2G /home/jack/projects
With no arguments, du works on the current directory. By default it walks the directory tree, prints the cumulative size of each directory (a directory's size includes everything under it), and ends with the total for the argument itself. Individual files are not listed unless you ask for them.
What to count and how deep
| Option | Effect |
|---|---|
-a, --all |
List every file, not only directories. |
-s, --summarize |
Print only a single total for each argument — no per-subdirectory breakdown. |
-d, --max-depth=N |
Show totals only down to N levels below each argument. -d 0 is the same as -s. |
-S, --separate-dirs |
Give each directory's own size, excluding its subdirectories. |
-c, --total |
Add a final grand-total line. |
--inodes |
Count inodes used rather than space used. |
What "size" means
| Option | Effect |
|---|---|
-h, --human-readable |
Sizes with unit suffixes — 4.2G — using powers of 1024. |
--si |
Likewise, using powers of 1000. |
-B, --block-size=SIZE |
Scale sizes to SIZE. |
-k / -m |
Use 1024-byte / 1024×1024-byte units. |
--apparent-size |
Report the apparent size of files — how much data they contain — rather than the disk space they occupy. The two differ for sparse files and because of block rounding. |
-b, --bytes |
Report plain byte counts. Equivalent to --apparent-size --block-size=1. |
Following symbolic links
By default du does not follow symbolic links.
| Option | Effect |
|---|---|
-L, --dereference |
Follow all symbolic links and count what they point to. |
-D, -H, --dereference-args |
Follow only the symbolic links named directly on the command line. |
-P, --no-dereference |
Follow no symbolic links. This is the default. |
-x, --one-file-system |
Do not cross into a different file system while walking. |
-l, --count-links |
Count a hard-linked file every time it is encountered, instead of once. |
Limiting the output
| Option | Effect |
|---|---|
--exclude=PATTERN |
Skip files and directories whose name matches PATTERN. |
--exclude-from=FILE |
Skip everything matching any pattern listed in FILE. |
-t, --threshold=SIZE |
Show only entries at least SIZE (or, with a negative SIZE, at most that big). |
--files0-from=F |
Take the list of files to measure from F, NUL-separated. - means standard input. |
--time[=WORD] |
Also show a timestamp — by default the latest modification time anywhere in the directory. |
-0, --null |
End each output line with a NUL character instead of a newline. |
-v, --verbose |
Report extra detail about what is being processed. |
Exit status
| Code | Meaning |
|---|---|
0 |
The report was produced. |
1 |
A file or directory could not be accessed. |
See also
Peios Learn
Built with Trail