Searching for a string in a gz compressed file

Tags:

Gzip is a compression technology available on most unix/linux systems.  Once in a while you might see a file such as filename.gz or filename.tar.gz and you may need to search through that file… I know some popular web server programs, such as apache, compress old log files to save space…

If you need to search through a .gz file, just use the zcat command (similar to cat):

zcat file.gz

You could even zcat the file then grep it’s contents or you could head or tail the file to see the start or end, respectively.  Pretty cool, now you don’t have to do a gunzip or tar xvfz.

zcat file.gz | grep ’some string’

or

zcat file.gz | head ’some string’

One note would be that greping the contents of a zcat will take some time, where using head or tail seems to execute a little faster. 

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
5 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.