Linux zcat Command Examples for Newbies

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
Linux zcat Command Examples for Newbies

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
Linux zcat Command Examples for Newbies

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
Linux zcat Command Examples for Newbies

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  
Linux zcat Command Examples for Newbies

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.

Source: tecmint.com

Be the first to comment

Leave a Reply

Your email address will not be published.


*