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 -sh * | sort -h shows what is eating your disk, biggest last

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

du -sh * 2>/dev/null | sort -h

Lists every folder in the current directory with its size, sorted so the biggest ones are at the bottom.

When a disk fills up, I want one answer: which folder is the big one? You do not need a special tool for that. Two standard commands do it.

du -sh * prints the total size of every item in the current folder in human-readable units. sort -h understands those units (K, M, G) and sorts them properly, so 900M does not land above 2G the way a plain sort would do it.

cd /var/lib
du -sh * 2>/dev/null | sort -h

The biggest item ends up at the bottom, right where your eyes are after the command finishes. Then cd into that folder and run it again. Two or three rounds usually find the culprit.

Two caveats. * skips hidden folders, so use du -sh .[!.]* * | sort -h if you suspect one. And on a path you do not own, du prints permission errors, hence the 2>/dev/null. Use sudo if you really need the numbers for system folders.

Further reading: du (GNU coreutils manual), sort -h (GNU coreutils manual), On this site: du -h -d1 | sort -h finds what is eating your disk, 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