How to grep Compressed Files?

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.*
  • 93 Пользователи нашли это полезным
Помог ли вам данный ответ?

Связанные статьи

Setting time with NTP in LINUX

NTP (Network Time Protocol) could be used to set time synced with ntp clocks, to do this use the...

Linux version & Operating System info

LINUX Version Info To learn the architecture and kernel version info use the shell command...

Compile and build Apache + MySQL + PHP from the source [cite]

This is a complete working solution to build Apache (httpd-2.2.25), MySQL (MySQL-5.6.14) and PHP...

Using vi Editor

Vi is the one of the mostly used editor in Linux via terminal. In most cases where Linux is used...

Build PHP5.5 on CentOS 6.4 with MSSQL Support [cite]

Most of the yum repos doesn’t include PHP5.5.X on current releases for the time being. So...