Quantcast
Channel: How do I deduplicate -exec expressions in a find command? - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 2

How do I deduplicate -exec expressions in a find command?

0
0

I have a find command that searches multiple file types using grep. For example, if want to search .js and .jsx files for the string foo, while excluding the dist directory, I'd type:

find . -path "./dist" -prune -or -iname "*.js" -exec grep "foo" {} + -or -iname "*.jsx" -exec grep "foo" {} +

Is there a way to rewrite this command so that the -exec isn't duplicated for each file type? I tried

find . -path "./dist" -prune -or -iname "*.js" -or -iname "*.jsx" -exec grep "foo" {} +

but all that searched just the .jsx files, not both .js and .jsx.


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images