This tutorial explains Linux “zcat” command, options and its usage with examples.
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.
zcat [ -f ] [ File … ]
zcat behaves as cat
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
$ 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.
$ zcat -f input-file
4. Paging the compressed file with zless / zmore.
$ zcat filename.gz | more $ zcat filename.gz | less
$ 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.
- Apply for Linux Internship
- Buy Linux Books
- Apply for Programming Internship
- Buy Information Technology Books
- Practice Programming MCQs