Sometimes you need to search the contents of .gz files in your system. Unfortunately, grep doesn’t work on compressed files. To overcome this, people usually advise to first uncompress the file(s), and then grep your text, after that finally re-compress your file(s)…
You don’t need to uncompress them in the first place. You can use zgrep on compressed or gzipped files.
To search in compressed file, execute the command :
root@ck [~]#zgrep ‘put-your-text-here’ /your-file-path-here/file.gz
Example : I want to grep ‘plugged’ in all of my exim_paniclog archived files.
root@ck [~]# zgrep ‘plugged’ /var/log/exim_paniclog.*