df and du answer the two halves of "where did my disk go?". df looks at whole filesystems; du walks directories and counts files. Together they turn a full-disk panic into a five-minute cleanup.
df: the filesystem view #
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/nvme0n1p2 476G 312G 140G 69% /
tmpfs 16G 0 16G 0% /dev/shm
The row to read is the one mounted on / (and /home if it is separate). When Use% passes 90, start looking.
One surprise: a filesystem can report as full while showing free space — deleted-but-held-open files. lsof | grep deleted finds the holding process, and restarting it frees the space.
du: the directory drill-down #
$ du -sh ~/projects
18G /home/ana/projects
-s summarises, -h makes units human. The drill-down pattern finds the hoarder:
$ du -h --max-depth=1 ~ | sort -rh | head
54G /home/ana
18G /home/ana/projects
12G /home/ana/.cache
Run it one level at a time, following the largest number down until you reach the actual files. rm then does the cleanup — ideally after a tar backup.
The pair in practice #
| Question | Command |
|---|---|
| How full is the disk? | df -h |
| How big is this folder? | du -sh folder |
| What should be cleaned first? | du -h --max-depth=1, then sort -rh |
| Are inodes exhausted? | df -i |
Disk pressure on remote machines is the same drill over ssh. More of the terminal notes series is in the journal.
