JustLikeThat JustLikeThat - 2 months ago 32
Linux Question

Mute gzip errors/warnings when using zgrep

I frequently use the commands like

find . ! -iname "*test*" -o -iname "*foo*" | xargs zgrep -ie first.*last -e last.*first


I use
zgrep
because it can
grep
through
.gz
files, and if the files aren't gzipped it simply uses
grep
. However I frequently get

gzip: copy.txt.gz: No such file or directory


logs that clutter the output of my searches. Is there any way to mute these
gzip
logs?

Answer

You can redirect the command standard error output to the null device.

find . ! -iname "*test*" -o -iname "*foo*" | xargs zgrep -ie first.*last -e last.*first 2>/dev/null