Summary

In this post we will learn about 3 simple commands by which we can read the files inside the compressed .gz file without extracting it.

Scenario

We have a log file called test.log and we compressed it by using command “gzip test.log” .
It will compressed the file into test.log.gz .

Now we want to read the test.log file which is compressed inside the file test.log.gz .

Install gzip command

To make these command working, first install the gzip package

sudo apt install gzip

3 Commands to read the .gz file in Linux

In this section, we have briefed about the 3 commands through which you can read the compressed .gz file. With the example, it is easy to understand.

zcat command

With the help of you can read the file contents inside compressed file. It will show the output similar to cat command.

Example:

zcat test.log.gz

zless command

The out of the zless command is similar to less command in Unix/Linux system.

Example:

zless test.log.gz

zmore command

The out of the zmore command is similar to less command in Unix/Linux system.

Example:

zmore test.log.gz

We hope the above 3 commands will be helpful. We have used these commands in scripting where we do not want to extract the file .

Read Some More Articles

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.