Linux Commands

zcat Linux Command

“When working with multiple files, it’s a common habit to compress them to save on space and is a good way to keep files organized. Linux offers various tools to compress files, such as gzip, and a compressed file can be decompressed using other tools like gunzip. How about viewing the contents of a compressed file without decompressing it? That’s where the zcat command comes in.

zcat is a Linux utility that displays the contents of a compressed file on the command line without decompressing the file. Besides, you can use it similar to the cat command to view the contents of normal files forcefully. We’ll cover all that in this guide.”

Working With zcat Command in Linux

The zcat works with compressed files without restoring their initial state. Without using zcat, you would need to decompress a file to see its contents and then recompress it again. That’s a hassle! Luckily, zcat does the same job more efficiently.

For our example, we will create different files and compress them.

We will use the touch and cat commands to create files, as shown in the image below.

With our files created, let’s go ahead and use the gzip command to compress them.

Note we now have two archive files; names.txt.gz and new1.list.gz.

1. Viewing contents of a single archive file using zcat

To access the contents of one compressed file, use the syntax below.

$ zcat [compressed-file]

Our output would be as shown in the image below. Note that zcat displays the file contents on the command line.

You can pipe the contents to a new file using the pipe command. Our new command will be:

$ zcat names.txt.gz | cat > output.txt

Confirm the contents of the newly created file using cat.

The output is the same as directly using zcat on the command line, but this method works best if you need to keep your command line clean and create a reference point.

2. Viewing contents of multiple archive files using zcat

Using zcat, you can display the contents of more than one file. The process is similar to viewing a single file with the addition of the other files to be viewed. The syntax is shown below.

$ zcat file1 file2 file_n

Let’s view the contents of our two archive files.

Similarly, you can choose to pipe their contents to a file as we did earlier.

3. Viewing normal files using zcat

If you need to view the contents of normal files using zcat, use the -f flag. With that, you can now use zcat like the cat command. Let’s create a file using cat and then use zcat to access its contents.

The syntax to view normal files is:

$ zcat -f file-name

You can also access the contents of multiple normal files simultaneously when viewing normal files, like in the image below.

5. Other zcat Options

-l or –list: this option displays the details of the compressed file. For instance, to get the details of our compressed file, the command would be:

$ zcat -l names.txt.gz

-v: when you need to add the verbose mode, add the -v flag. For instance, we can use the -v with the previous command. The output would be:

You now get more details with the same command, including the date and time.

-q: opposite to adding verbosity, you can choose to suppress all warnings when using commands with zcat. For this, add the -q option.

Note how the -q suppressed many details in the output.

–help: to open the help page, the command is:

$ zcat --help


Having the zcat command by your side is great when working with archive files. We’ve seen the different ways you can use it to access the contents of your archived files using examples. There are various ways to get creative with the command. Thanks to this article, you should be good to go. Try it today!

About the author

Denis Kariuki

Denis is a Computer Scientist with a passion for Networking and Cyber Security. I love the terminal, and using Linux is a hobby. I am passionate about sharing tips and ideas about Linux and computing.