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 -fstype matches files by the type of filesystem they live on

Find
~/tips/tip-find-fstype-printf-f-filesystem-type

find / -maxdepth 1 -fstype proc

Selects files that sit on a given filesystem type, and -printf %F shows which type that is.

Most find tests look at the file itself: its name, size or age. This one looks at the disk the file lives on, which is handy once you have network shares or virtual filesystems mounted.

find / -maxdepth 1 -fstype proc
/proc

-fstype TYPE is true for files on a filesystem of that type. You don’t have to guess the type names: the manual says that -printf with the %F directive shows them, and that the value can be used for -fstype.

find / -maxdepth 1 -printf '%p %F\n'
/ ext4
/etc ext4
/boot ext4
/proc proc

That list is trimmed. On a typical Linux system /proc is the only top-level entry with type proc and the rest is ext4, which is why the first command prints just /proc.

The test earns its keep together with -prune, to keep a search out of a filesystem you don’t want to walk. Without pruning, find / -maxdepth 2 -name cpuinfo prints /proc/cpuinfo. With the filesystem pruned, the same search finds nothing:

find / -maxdepth 2 -fstype proc -prune -o -name cpuinfo -print

The same idea works for a network type like nfs, the first thing I’d prune on a machine with shares mounted. That type was not tried here; it follows the manual, so check it on your own system first. Note the -o: -prune only skips the folder, and -print after the -o handles everything that was not pruned.

Caveat: the type names depend on the system. The manual calls its own list incomplete and says the valid names vary between versions of Unix. Check with %F first and copy the name from there.

Further reading: find(1) manual page

More Find tips 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 find / -xdev -user olduser -ls 2>/dev/null All Find tips (46) All topics

Link