Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Does there exist a magical shell piping which would allow easily to grep through bunch of .gz log files without needing to extract them somewhere?

.gz files are Apache logs, result of log rotation. I'd like to quickly check how often certain URIs are accessed in the past.

share|improve this question
up vote 21 down vote accepted

The zgrep program is available for Linux (and perhaps some Unix too). This will decompress the files and then grep through them.

share|improve this answer
+1. See also: zcat, zegrep, zmore, zless... – SmallClanger May 11 '11 at 12:15

Should you for some reason lack zgrep you can do the same thing with gunzip and a pipe:

gunzip -c <filename.gz> | grep <whatever you want to grep for>
share|improve this answer

You can just use zgrep to grep through compressed files.

If you need to use a specific grep, you can set the GREP environment variable:

export GREP=/bin/egrep
share|improve this answer

How about zgrep? Seems to be installed on Mac OS and Ubuntu 11.04.

share|improve this answer

I usually use:

zcat filename.gz | less

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.