exclude a folder from find
Search with find without going into folders like .git or node_modules.
Steps
-
find . -path ./node_modules -prune -o -name '*.js' -printevery .js file, without going into node_modules
-
find . -not -path '*/.git/*' -name '*.md'every .md file outside .git folders (still walks them)
-
find . \( -name .git -o -name node_modules \) -prune -o -type f -printevery file, skipping both folders
-
find . -name '*.log' 2>/dev/nullhide the permission denied messages
Notes
-prunedoes not go into the folder at all, so it is fast on big trees;-not -pathstill walks it.
Commands used
findfd
Each has a page in lore: lore find opens it.
Related recipes
- find a fileFind a file by its name, by when it changed, or by what is written in it.
- find files containing a textSearch every file under a folder for a word or a phrase, and show where it is.
- add to the end of a fileAdd lines to a file without replacing it, also to a file only root can write.
- argument list too long"Argument list too long" from rm, cp or mv: too many files for one command line. Hand them over in batches.