Bash 使用exec查找表达式

Bash 使用exec查找表达式,bash,find,Bash,Find,我和find有点麻烦。这并没有达到我的预期: find . -iname "*.hh" -or -iname "*.h" -exec grep -inH "IDENTIFIER" {} \; 我希望它在*.hh和*.h文件中都会变灰,但它只会变灰-iname“*.h”的结果。我求助于使用xargs来解决它 find . -iname "*.hh" -or -iname "*.h" | xargs grep -inH "IDENTIFIER" 但是有没有一种方法可以使用-exec而不用像这样写

我和find有点麻烦。这并没有达到我的预期:

find . -iname "*.hh" -or -iname "*.h" -exec grep -inH "IDENTIFIER" {} \;
我希望它在*.hh和*.h文件中都会变灰,但它只会变灰-iname“*.h”的结果。我求助于使用xargs来解决它

find . -iname "*.hh" -or -iname "*.h" | xargs grep -inH "IDENTIFIER"
但是有没有一种方法可以使用-exec而不用像这样写两遍:

find . -iname "*.hh" -exec grep -inH "IDENTIFIER" {} \; -or -iname "*.h" -exec grep -inH "IDENTIFIER" {} \;
你可以说:

find . \( -iname "*.hh" -o -iname "*.h" \) -exec ...
要同时查找*.hh和*.h文件,可以说:

find . \( -iname "*.hh" -o -iname "*.h" \) -exec ...

要同时查找*.hh和*.h文件。

还可以使用grep的regex选项:


find-regex'.*\.hh?'-exec grep-inH“标识符”{}

您还可以使用grep的regex选项:

find-regex'.*\.hh?'-exec grep-inH“标识符”{}