Quote:
Originally Posted by rtmistler
Directories are type f also. This is why you see that. There are probably options for the command to suppress errors.
|
Excuse me, but "-type f" in the
find command specifically matches "ordinary files".
To the OP, the problem with your original expression is operator precedence and binding, and also a misunderstanding of the "-prune" action.
Quote:
Originally Posted by Jrubiando
Code:
% find . -type f ! \( -name "*.vue" -or -name "*.slim" -or -name "*.js" -or -name "*.erb" \) -o -path './vendor' -prune -o -path './public' -prune -o -path './spec' -prune -o -path './node_modules' -prune -o -path './config' -prune -exec egrep 'extra_fields' {} \; -print
|
The operands of
find that follow the search path operands form a Boolean expression evaluated according to precedence and binding rules. Your "-type f" is AND-ed only with the immediately following negated parenthesized term, and does not affect any of the OR-ed terms that follow. Also, the "-exec egrep ..." action term is bound only to the immediately preceding "-path './config' -prune" term, and will not be executed for anything else. And finally, matching a "-prune" test does prevent descending into that directory, but does not block the directory name itself.
Since the only actions in your expression are the final "-exec egrep 'extra_fields' {} \; -print" terms, and those are bound only to the "-path './config' -prune" term, the rest of the expression is effectively ignored and you are left with just
Code:
find . -path './config' -prune -exec egrep 'extra_fields' {} \; -print
which is far from what you intended.