I want to look for a particular pattern in a directory of files and want to exclude certain patterns while the result is displayed.
I use the following command
find . -type f -exec grep -il 'foo' {} \; | find . -not -name "*.jar" -not -name "*.gz" -not -name "*.log" 2>/dev/null
when the result is displayed, I see the following error message
find: grep terminated by signal 13
Can someone please guide me as to why this error message is there and if there is a better command to use for getting the desired result (basically excluding jar files or log files or some other type of files from the result set)?
I think you're trying to use find
as grep
in the second half of that pipeline; find
doesn't work like that. What you should do is have it all in one command:
find . -type f -not -name "*.jar" -not -name "*.gz" -not -name "*.log" -exec grep -il 'foo' {} + 2>/dev/null
Or
find . -type f -not -name "*.jar" -not -name "*.gz" -not -name "*.log" -exec grep -qi 'foo' {} \; -print 2>/dev/null
Or let grep
traverse the tree itself and filter the names after (using grep
, not find
):
grep -irl foo . | grep -v -e '\.jar$' -e '\.gz$' -e '\.log$'
find . | grep -v "jar$" | grep -v "log$" | grep -v "gz$"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With