Recursive zgrep not working

I have a directory hierarchy that contains numerous .gz files. I want to be able to recursively grep them for the string "foo". From what I've read online the following should work:

zgrep -R -H "foo" .

However, this never returns any results. If I replace the dot with the name of a file it does work. For example,

zgrep -R -H "foo" myFile.gz

however, obviously, this no longer will be recursive.

I know "foo" is in some of the files because the following command returns many results:

find . -iname "*.gz" | xargs zgrep "output" | less

Does anyone know why my recursive zgrep command is not working. I'm on a RHEL linux box


The way I usually do is:

zgrep "foo" $(find . -name "*.gz")

or (however, the file name will be printed before each result instead of each line --not just the files with matches--):

find . -name "*.gz" -print -exec zgrep "foo" {} \;

If that command returns "Argument list too long", try this way:

for I in $(find . -name "*.gz"); do zgrep "foo" $I; done

Your almost there. Try this:

zgrep -R -H "foo" *.gz

EDIT: Hmmmm.... intriguing!

According to my zgrep, -R (Recursive) is not an option. Its simply not supported. Id have a check to see what the man page of your zgrep says.

One alternative, which depends on only one level of subdirectories is to do this:

zcat */*.gz | grep <needle>

But I would suggest that your find command is probably better!


You have to install zutils. This will replace the default and limited zgrep on your system with a recursive-able one.

On debian based systems you run apt-get install zutils then you can zgrep -rH myword . and use most of the other parameters from grep you know and love.