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 #

OptionEffect
-a, --allList every file, not only directories.
-s, --summarizePrint only a single total for each argument — no per-subdirectory breakdown.
-d, --max-depth=NShow totals only down to N levels below each argument. -d 0 is the same as -s.
-S, --separate-dirsGive each directory's own size, excluding its subdirectories.
-c, --totalAdd a final grand-total line.
--inodesCount inodes used rather than space used.

What "size" means #

OptionEffect
-h, --human-readableSizes with unit suffixes — 4.2G — using powers of 1024.
--siLikewise, using powers of 1000.
-B, --block-size=SIZEScale sizes to SIZE.
-k / -mUse 1024-byte / 1024×1024-byte units.
--apparent-sizeReport 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, --bytesReport plain byte counts. Equivalent to --apparent-size --block-size=1.

By default du does not follow symbolic links.

OptionEffect
-L, --dereferenceFollow all symbolic links and count what they point to.
-D, -H, --dereference-argsFollow only the symbolic links named directly on the command line.
-P, --no-dereferenceFollow no symbolic links. This is the default.
-x, --one-file-systemDo not cross into a different file system while walking.
-l, --count-linksCount a hard-linked file every time it is encountered, instead of once.

Limiting the output #

OptionEffect
--exclude=PATTERNSkip files and directories whose name matches PATTERN.
--exclude-from=FILESkip everything matching any pattern listed in FILE.
-t, --threshold=SIZEShow only entries at least SIZE (or, with a negative SIZE, at most that big).
--files0-from=FTake 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, --nullEnd each output line with a NUL character instead of a newline.
-v, --verboseReport extra detail about what is being processed.

Exit status #

CodeMeaning
0The report was produced.
1A file or directory could not be accessed.

Edit this page