zcat Command in Linux with Examples

This tutorial explains Linux “zcat” command, options and its usage with examples.

zcat – Expands a compressed file to standard output.

DESCRIPTION

zcat uncompresses either a list of files on the command line or its standard input and writes the uncompressed data on standard output. zcat will uncompress files whether they have a .gz suffix or not.

SYNOPSIS

zcat [ -f ] [ File … ]

OPTION :

-f
zcat behaves as cat

advertisement
advertisement

EXAMPLES

1. To view the contents of zipped file

$ cat file1.txt
abc
def
ghi
$ gzip file1.txt
$ zcat file1.txt.gz 
abc
def
ghi

2. View a gzipped file which don’t have the gz suffix

Note: Join free Sanfoundry classes at Telegram or Youtube
$ cat > test-file.txt
This is a test file used for gunzip and zcat testing
 
zcat is awesome command.  
$ gzip test-file.txt
 
$ mv test-file.txt.gz test-file-no-ext
 
$ gzip -d test-file-no-ext
gzip: test-file-no-ext: unknown suffix -- ignored
 
$ zcat test-file-no-ext
This is a test file used for gunzip and zcat testing
 
zcat is awesome command.

If you try to uncompress a gzipped file which don’t have the gz suffix with “gunzip” or “gzip -d” command you will face error like in the example test-file-no-ext. Hence using zcat on it works just as with any other .gz file.

3. Display the file content without worrying about whether it is compressed or not

When you are not sure whether a file is compressed or not, you can still view the file without worrying about it’s compression status as shown below.

advertisement
$ zcat -f input-file

4. Paging the compressed file with zless / zmore.

$ zcat filename.gz | more
$ zcat filename.gz | less

(or)

advertisement
$ zless filename.gz
$ zmore filename.gz

With paging, if the content of the file goes beyond the screen size, then the content can be displayed line by line using the more and less commands.

Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.

If you wish to look at all Linux commands and their usage examples, go to Linux Commands Tutorial.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.