I'm trying to locate nested YAML and HTML files to replace a string with sed after creating the list; I'm not sure I fully understand how to use the -prune option, here's what I have:

find . -type f -name '*.yaml' -or -name '*.html' \
    -and -path './.git/*' -or -path '*/node_modules/*' -prune

For which I still get HTML files under node_modules directories

2 Answers 2


If you'd like to prune any directory called either .git or node_modules from the search tree, you would use

-type d \( -name .git -o -name node_modules \) -prune

This would cause find to not even enter these directories (the -type d is not strictly necessary, but I'll use it here for symmetry with -type f; see below).

Then you would add the other conditions,

-type d \( -name .git -o -name node_modules \) -prune -o \
-type f \( -name '*.yaml' -o -name '*.html' \) -print

Ending up with

find . \
    -type d \( -name .git -o -name node_modules \) -prune -o \
    -type f \( -name '*.yaml' -o -name '*.html' \) -print

Any action that you'd like to take on the pathnames that passes all tests should be done in place of the -print.

Note that the default logical operation between two predicates is -a (AND).

  • Thank you!, it indeed does work and the way that you construct the query makes sense
    – Tristian
    Mar 22, 2019 at 21:15
man find

Is a great place to look for more info on find.

This should work for you.

find . \
    -type f \
    '(' -name '*.yaml' -or -name '*.html' ')' -and \
    -not '(' -path './.git/*' -or -path '*/node_modules/*' ')'

Note the use of parentheses, and the need to quote them due to their being intrinsic built-in syntax to bash (and most other shells).

  • 1
    Thank you for your answer, I did use the manual, however I found the -prune explanation and usage a bit confusing.
    – Tristian
    Mar 22, 2019 at 21:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.