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 * skips hidden folders, and they can hold half your disk

Disk
~/tips/tip-disk-du-hidden-folders

du -sh -- .[!.]* * 2>/dev/null | sort -h

Includes dot folders like .cache in a du overview, where the usual glob leaves them out.

du -sh * | sort -h is the classic way to see what fills a folder. In a home folder it misses the biggest culprits, because * doesn’t match names that start with a dot.

Folders like .cache, .local, .npm and .docker can be huge, and the shell leaves them out of *. I’d add a second pattern for them:

du -sh -- .[!.]* * 2>/dev/null | sort -h

.[!.]* means a dot followed by anything that isn’t a second dot, so it matches the hidden files and folders but not . and .., which would make du count everything twice. The -- protects against a file name that starts with a dash. A hidden cache folder doesn’t show up at all with plain *, and can top the list with the extra pattern.

There’s a simpler route that avoids the shell patterns:

du -h -d1 . | sort -h

That lists every folder in the current one, hidden ones included, plus a total for .. It leaves out loose files in the top level, though.

The extra pattern misses names that start with two dots, like ..cache, which are rare. And in a folder with no hidden files at all, bash passes the literal .[!.]* to du, which then prints an error; the redirect hides it.

Further reading: du invocation, GNU coreutils, Bash manual: filename expansion

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 ls -l /dev/disk/by-id/ All Disk tips (44) All topics

Link