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 -L follows symlinked folders that find normally skips

Find
~/tips/tip-find-l-follow-symlinks

find -L /srv/media -name '*.mkv'

Makes find search inside folders that are reached through symbolic links.

By default find does not follow symlinks. A link to another folder shows up as a link, and whatever sits behind it stays out of the search.

Put -L in front of the path to follow every link:

find -L /srv/media -name '*.mkv'

In a folder with a symlink to another disk, you might get two results without -L and three with it, because the file behind the link is included.

There’s a milder version, -H. It only follows links that you name on the command line, not the ones it meets along the way. That’s handy when the starting point is itself a link, like /srv/current pointing at a release folder, and you don’t want to wander everywhere else:

find -H /srv/current -name '*.conf'

-L has side effects. Links that point back up the tree make loops; GNU find notices them and prints a warning instead of running forever, but the output gets noisy. -type l stops matching anything, since links are now treated as what they point to; use -xtype l for that. And with -L, a combination with -delete is something I’d never run: it can reach files far outside the folder you meant.

Further reading: find(1) manual page, GNU findutils manual

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