find -prune: Skip node_modules and .git
find -prune tells find not to descend into a matched directory.
Skipping node_modules and .git makes searches dramatically faster and avoids matching vendored files. The -prune idiom looks odd but is precise.
What it does
find -prune, when it matches a directory, stops find from recursing into it. It is almost always paired with -o (OR) and a following action, in the form: match-the-dir -prune -o real-test -print. The -prune branch swallows the directory, and the -o branch handles everything else.
Common usage
find . -name node_modules -prune -o -type f -name '*.js' -print
find . \( -name .git -o -name node_modules \) -prune -o -type f -print
find . -path '*/.git' -prune -o -name '*.log' -printOptions
| Element | What it does |
|---|---|
| -prune | Do not descend into the currently matched directory |
| -o | OR: try the right side when the left side is false |
| Required on the action side so pruned dirs are not printed | |
| \( ... \) | Group several names to prune together |
In CI
The trailing -print is not optional. Without it the default action prints everything including the pruned directory names. The pattern is: name-of-dir-to-skip -prune -o your-real-criteria -print.
Common errors in CI
If pruned directories still show up, the action side is missing its explicit -print, so find falls back to printing all matches. If find still descends into node_modules, the -prune predicate did not match the directory name (check -name vs -path). Parentheses must be escaped as \( \) or quoted so the shell does not eat them.