find string inside a gzipped file in a folder find string inside a gzipped file in a folder linux linux

find string inside a gzipped file in a folder


zgrep will look in gzipped files, has a -R recursive option, and a -H show me the filename option:

zgrep -R --include=*.gz -H "pattern match" .

OS specific commands as not all arguments work across the board:

Mac 10.5+: zgrep -R --include=\*.gz -H "pattern match" .

Ubuntu 16+: zgrep -i -H "pattern match" *.gz


You don't need zcat here because there is zgrep and zegrep.

If you want to run a command over a directory hierarchy, you use find:

find . -name "*.gz" -exec zgrep ⟨pattern⟩ \{\} \;

And also “ls *.gz” is useless in for and you should just use “*.gz” in the future.


how zgrep don't support -R

I think the solution of "Nietzche-jou" could be a better answer, but I would add the option -H to show the file name something like this

find . -name "*.gz" -exec zgrep -H 'PATTERN' \{\} \;