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

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
Difficulty Easy (rss)
Root privileges No
Requirements z* commands
Time 1m
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.

ADVERTISEMENTS

Syntax

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 1.2.3.4 IP address using grep command like syntax:

zgrep '1.2.3.4' 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
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
4 comments… add one
  • deepak Nov 12, 2013 @ 13:32

    I use below command for the same purpose.

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

  • Tim Brust Nov 14, 2013 @ 10:36

    Thanks – great as always :)

  • Rick Sep 18, 2014 @ 9:37

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

  • arjunvarma Jun 11, 2017 @ 10:12

    Thank you

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.