How can I do an "or" search with find?
find
’s “or” operator is -o
:
find . -name "*.pem" -o -name "*.crt"
It is short-circuiting, i.e. the second part will only be evaluated if the first part is false: a file which matches *.pem
won’t be tested against *.crt
.
-o
has lower precedence than “and”, whether explicit (-a
) or implicit; if you’re combining operators you might need to wrap the “or” part with parentheses:
find . \( -name "*.pem" -o -name "*.crt" \) -print
In my tests this is significantly faster than using a regular expression, as you might expect (regular expressions are more expensive to test than globs, and -regex
tests the full path, not only the file name as -name
does).