Normally, files compressed using gzip can be restored to their original form using gzip -d or gunzip commands. What if you want to view the contents of a compressed file without uncompressing it? For this purpose, you need the zcat command utility.

Read Also: 18 tar Command Examples in Linux

Zcat is a command line utility for viewing the contents of a compressed file without literally uncompressing it. It expands a compressed file to standard output allowing you to have a look at its contents. In addition, zcat is identical to running gunzip -c command. In this guide, we will explain zcat command examples for beginners.

1. The first example shows how to view contents of a normal file using cat command, compress it using gzip command and view the contents of the zipped file using zcat as shown.

$ cat users.list $ gzip users.list
$ zcat users.list.gz
View Compressed File Contents in Linux

View Compressed File Contents in Linux

2. To view multiple compressed files, use the following command with filenames as shown.

$ zcat users.list.gz apps.list.gz
View Multiple Compressed Files Content in Linux

View Multiple Compressed Files Content in Linux

3. To view contents of normal files use the -f flag, similar to cat command, for example.

$ zcat -f users.list
View Linux File Contents

View Linux File Contents

4. To enable pagination, you can use the more and less commands as shown (Also read: Why ‘less’ is Faster Than ‘more’ Command in Linux).

$ zcat users.list.gz | more
$ zcat users.list.gz | less

5. To get the properties (compressed size, uncompressed size, ratio – compression ratio (0.0% if unknown), uncompressed_name (name of the uncompressed file) of a compressed file, use the -l flag.

$ zcat -l users.list.gz 
View Compressed File Properties in Linux

View Compressed File Properties in Linux

6. To suppress all warnings, use the -q flag as shown.

$ zcat -q users.list.gz

For more information, see the zcat man page.

$ man zcat

You might also like to read these following related articles.

  1. ccat – Show ‘cat Command’ Output with Syntax Highlighting or Colorizing
  2. How to Use ‘cat’ and ‘tac’ Commands with Examples in Linux
  3. Manage Files Effectively using head, tail and cat Commands in Linux
  4. How to Backup or Clone Linux Partitions Using ‘cat’ Command

That’s all! In this short article, we’ve explained zcat command examples for beginners. Share your thoughts with us in the comments section below.

Facebook Comments

More Stuff

What you missed in cybersecurity this week It’s been a busy week — it’s tough to keep up with all the cybersecurity news. We’ve collected some of the biggest cybersecurity stories from the week...
Boston Dynamics debuts the production version of SpotMini Last year at our TC Sessions: Robotics conference, Boston Dynamics announced that SpotMini will be its first commercially available product. A revampe...
Platforms Want Centralized Censorship. That Should Scare You In the immediate aftermath of the horrific attacks at the Al Noor Mosque and Linwood Islamic Centre in Christchurch, New Zealand, internet companies f...
Want a Tech Job? Silicon Valley Is Still Your Best Bet Communities across the country are trying to lure high-tech jobs away from Silicon Valley. It doesn’t seem like that should be hard. Silicon Valley is...
Spread the love

Posted by News Monkey