Vol. I · No. 46The command line sectionSat, 10 Oct 2026
Linux · disks & space

du

what is taking the space

du — disk usage — walks a directory tree and totals the space taken by every file beneath it. Where df reports on whole filesystems, du reports on directories, so it is how you track a full disk down to the thing that filled it.

Summarise, sort, and descend: du -sh * | sort -h finds the largest directory at each level.

Measures
Directories
everything beneath them
One total
-s
instead of every sub-directory
Readable sizes
-h
K, M and G
Pair with
sort -h
to put the largest last

At the terminal

Read the session first, then the notes: each numbered line in the output is answered by the note with the same number.

root@netflow — bashcoreutils
# du -sh /var/log
12.3G /var/log
2# du -h --max-depth=1 /var | sort -h | tail -4
1.1G /var/cache
2.3G /var/log
36.8G /var/lib
411G /var
Illustrative session · names, sizes and dates are examples, and every address is from a documentation or private range
Reading the output

What the numbered lines are telling you

1
One line: the total for the directory

-s summarises and -h makes the size readable. Without -s, du prints a line for every sub-directory beneath.

2
One level deep, sorted

--max-depth=1 lists each directory directly under /var. sort -h orders by size, understanding G and M, and tail keeps the largest four.

3
The largest child

/var/lib holds 6.8 GB — databases and container images usually live there. That is where to look next.

4
The last line is the parent’s total

du always ends with the directory it was given. It is larger than the children shown because smaller directories were cut off by tail.

Switches

A switch changes how the command behaves. These are the ones used day to day; man du lists the rest. Single-letter switches can usually be joined, so -l -a may be written -la.

-s
Summarise: print one total for each argument, not every sub-directory.
-h
Human-readable sizes: K, M, G.
-a
All: report files as well as directories.
-c
Add a grand total at the end.
-d NUM
Report only NUM levels deep. --max-depth=NUM is the same.
-x
Stay on one filesystem: do not cross into other mounted disks.

Variations worth knowing

The same tool, pointed at a narrower question. These four cover most of what it is reached for day to day.

du -sh * | sort -h

Sizes everything in the current directory, largest last.

du -ah . | sort -h | tail -10

Finds the ten largest files and directories beneath here.

sudo du -xh --max-depth=1 / | sort -h

Sizes the top of the tree. -x stays on the root filesystem and skips other disks.

du -sh ~/.cache

Checks one directory — caches are often the easiest space to win back.

In cybersecurity

Disk usage that grows without explanation is one of the plainer signs that something is wrong.

Sudden growth

A log growing by gigabytes a day may be an attack being recorded. A large new directory in /tmp or a home directory may be data staged for removal.

Run it as root to see everything

As an ordinary user du skips the directories it cannot read and under-reports. The "Permission denied" lines are the parts it missed.

Space that du cannot find

If df says the disk is full but du cannot account for it, a deleted file is probably still held open by a running process. "lsof +L1" lists them.

Filed under

Disks & space

Read alongside