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 -name node_modules -prune skips a folder instead of walking it

Find
~/tips/tip-find-prune-skip-directory

find . -name node_modules -prune -o -type f -name '*.js' -print

Skips a whole directory tree during a search, such as a dependency folder.

Searching a project with find also searches every dependency folder. -prune stops find from descending into it.

find . -name node_modules -prune -o -type f -name '*.js' -print

Read it as: if the name is node_modules, prune it, otherwise (-o) test for files ending in .js and print them. The explicit -print is needed, because without it the pruned directory is printed as well. -prune does nothing when -depth is in effect, and -delete turns -depth on, so pruning and deleting in one command does not work. The same pattern works for .git or any cache folder that you want to leave out.

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