brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: du -h -d1 | sort -h finds what is eating your disk

Disk
~/tips/tip-linux-du-sort-h

sudo du -h -d1 -x /var | sort -h

Lists directory sizes with the biggest last, so you see what fills the disk.

Disk full, and no idea where it went. This one line gets me to the answer faster than any graphical tool.

From the directory you want to inspect:

sudo du -h -d1 -x /var | sort -h

-d1 shows totals one level deep, -h prints sizes like 4.2G, and -x stays on one filesystem so other mounts do not distort the picture. The important part is sort -h: it understands those human sizes, so the biggest directories end up at the bottom, right above your prompt.

Then repeat the command inside the biggest directory and you drill down in a few steps.

The caveat is permissions. Without sudo, du skips directories you cannot read and prints errors, so the totals can be too low. Also -d is the GNU short form of --max-depth; the BSD and macOS du uses the same letter but with slightly different behaviour.

If you want something friendlier, ncdu does the same job with an interactive screen, but it is usually not installed by default. This pipeline is on every server I log into, so I reach for it first.

Further reading: du man page (GNU coreutils), sort man page, On this site: du -sh * | sort -h shows what is eating your disk, biggest last, On this site: lsblk -f shows filesystems, labels and UUIDs in one view

More Disk tips sudo e2freefrag /dev/sdb1 sudo smartctl -a --json /dev/sda | jq '.smart_status.passed' lsscsi -s udisksctl power-off -b /dev/sdX du -sh — .[!.]* * 2>/dev/null | sort -h All Disk tips (44) All topics

Link