Unix / Linux: cat .GZ Compressed Text File On Screen

by on November 11, 2013 · 3 comments· LAST UPDATED November 11, 2013

in , ,

To save the disk space on my Linux based nas (network storage server), I have compressed thousands of reports[0-1000].txt files using gunzip program. However, I need to cat .gz file (or open in vim text editor) for reference purposes. I have a log files stores on my nas server in compressed format using gzip command. How do I display compressed Apache log file without using cat command? How to display the contents of gzip text files in screen without unzipping?

Tutorial details
DifficultyEasy (rss)
Root privilegesNo
Requirementsz* commands
Estimated completion time1m
You can easily display compressed files on Linux or Unix without using using the cat command, less, or more command. In this example, show the contents of a text file called resume.txt.gz that has been compressed using gzip and friends. Open the Terminal and then type the following commands.


Display resume.txt.gz on screen using cat command like syntax:

zcat resume.txt.gz

Display access_log_1.gz on screen at a time:

zmore access_log_1.gz

Or try zless (less command):

zless access_log_1.gz

Search access_log_1.gz for IP address using grep command like syntax:

zgrep '' access_log_1.gz

You can use egrep command like syntax:

egrep 'regex' access_log_1.gz
egrep 'regex1|regex2' access_log_1.gz
See also
Tweet itFacebook itG+ itDownload PDF versionFound an error/typo on this page?

{ 3 comments… read them below or add one }

1 deepak November 12, 2013 at 1:32 pm

I use below command for the same purpose.

gzip -cd access_log_1.gz | egrep ‘regex1|regex2′


2 Tim Brust November 14, 2013 at 10:36 am

Thanks – great as always :)


3 Rick September 18, 2014 at 9:37 am

Found I had to use below on Solaris 10
gzcat gzdiff gzexe gzforce gzip gzmore
gzcmp gzegrep gzfgrep gzgrep gzless gznew


Leave a Comment

Tagged as: , , , , ,

Previous Faq:

Next Faq: