Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: Z commands for accessing the compressed files easily  (Read 2600 times)

0 Members and 1 Guest are viewing this topic.

sanjaym

  • Guest
Z commands for accessing the compressed files easily
« on: November 09, 2017, 11:44:16 am »
Z commands for accessing the compressed files easily
==================================

Log rotation is a common thing in Linux servers for saving the disk space.
We can compress the logs by using log rotation so that only the latest
file will be available to read readily and alll other files will be
compressed. The problem comes when we want to open and see an older log
which is compressed. We can do this by uncompressing the log file and
then recompress it after our use to save disk space. But we don't have to
do this many tasks to achieve our goal. We can instead use z commands.

zcat command for viewing a compressed log file
-----------------------------

# zcat modsec_audit.log-20170820.gz

Sometimes we don't want to see the whole 500MB log to search for a
word/pattern. For this, we can use zgrep command.

zgrep command for searching a pattern from a compressed file
------------------------------------------------------------

# zgrep  "<search pattern>" modsec_audit.log-20170820.gz

We can use all options with zgrep that  can be used with normal grep tool.

# zgrep -B2  "241783" modsec_audit.log-20170912.gz


We can also use zless command which is equivalent to less.