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: find -type d -empty lists the folders with nothing in them

Find
~/tips/tip-find-empty-directories

find . -mindepth 1 -type d -empty

Lists empty files and empty directories under a path.

Leftover empty folders pile up after a clean-up or a failed sync. find has a test for them.

find . -mindepth 1 -type d -empty
find . -type f -empty

-empty matches a file of zero bytes or a directory without entries. -mindepth 1 keeps the starting folder out of the list. Looking at the list first is worth the few seconds, since a folder like .git/refs/tags or a mount point can be empty on purpose. If you do delete, find . -mindepth 1 -type d -empty -delete also removes folders that become empty after their children went.

Further reading: find manual page

More Find tips find / -maxdepth 1 -fstype proc find /backup -name '*.gz' ! -exec gzip -t {} \; -print 2>/dev/null find /srv/downloads -type f -size +100M -size -1G -exec ls -lh {} + find /srv/data -depth -print find /srv -xdev -samefile /srv/downloads/movie.mkv All Find tips (46) All topics

Link