About Linux FAQ

Browse More FAQs:

Grep compressed (.gz) files at a shell prompt

Posted by Vivek Gite [Last updated: January 29, 2008]

Q. I've lots of .gz files in my directory and I'd like to search them using grep. Unfortunately, grep is not working on my compressed file How do I write a script to automate entire procedure to grep some compressed files. Do I have to uncompress them first and run grep over them?

A. No you don't have to uncompress file. Linux and UNIX comes with z-commands. zgrep invokes grep on compressed or gzipped files. All options specified are passed directly to grep.

To search .gz file called test.gz, enter:
$ zgrep 'word-to-search' /path/to/test.gz
$ zgrep 'GET /faq/a-long-url/' /path/to/access.log.gz

You can run zcat command to display file on screen:
$ zcat file.gz

Update: See list of all z-commands

Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

Related Other Helpful FAQs:

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , ,

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.