Grep compressed (.gz) files at a shell prompt
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:
- How do I list files inside compressed tar ball (gzip’d tar’d) archive?
- List the contents of a tar or tar.gz file
- How To Open .TBZ ( tar.bz2 ) File Under Linux / UNIX
- Linux/UNIX: Rules for naming file and directory names
- Linux / UNIX command to open .gz files
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!
Tags: , grepping compressed files, zcat command, zgrep command



Recent Comments
Today ~ 13 Comments
Today ~ 2 Comments
Yesterday ~ 8 Comments
Yesterday ~ 4 Comments
Yesterday ~ 8 Comments