Why in Linux (Debian 8)
touch 1.cpp 1.h
find . -name "*.cpp" -o -name "*.h" -exec echo {} \;
outputs only 1.h
while
find . -name "*.cpp" -o -name "*.h"
outputs both? Is it a bug or feature?
I think once you used -or
operator, then you've to keep it consistent in order to avoid ambiguous order of logical operations when you have multiple conditions connected using logical OR.
It seems the -exec
part is grouped together with the second -name "*.h"
.
So in order to make it work correctly, you've to add the brackets as below:
find . '(' -name '*.cpp' -o -name '*.h' ')' -exec echo {} ';'
Remember: The parentheses must be quoted or escaped with a backslash to prevent them from being interpreted as special shell characters.
Alternatively combine few extensions into one by using -regex
:
find . ! -regex ".*\.\(cpp\|h\)" -exec echo {} \;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments