When I'm using
find . -type f -name "*.htm*" -o -name "*.js*" -o -name "*.txt"
it finds all the types of file. But when I add -exec
at the end:
find . -type f -name "*.htm*" -o -name "*.js*" -o -name "*.txt" -exec sh -c 'echo "$0"' {} \;
it seems it only prints .txt
files. What am I doing wrong?
Note: using MINGW (Git Bash)
Best Answer
is short for:
That is, because no action predicate is specified (only conditions), a
-print
action is implicitly added for the files that match the conditions.(and, by the way, that would print non-regular
.js
files (the-type f
only applies to.htm
files)).While:
is short for:
For
find
(like in many languages), AND (-a
; implicit when omitted) has precedence over OR (-o
), and adding an explicit action predicate (here-exec
) cancels the-print
implicit action seen above. Here, you want:Or:
To avoid running one
sh
per file.