How to Use the bzcat Command to Read Compressed Files in Linux

The standard cat command is one of the most frequently used tools in Linux for reading text files and printing their contents to the screen. However, if you attempt to use cat on a compressed archive (like a .bz2 file), your terminal will be instantly flooded with unreadable, garbled binary characters, and you might even break your terminal session. To read the text hidden inside a bzip2 compressed file without having to fully extract it to your hard drive first, you must use the bzcat command.

How bzcat Works

The bzcat command is specifically designed to handle files compressed with the bzip2 algorithm. When you execute bzcat against an archive, it temporarily uncompresses the data directly into your system’s RAM. It then streams the raw text to standard output (your monitor). Because the data is never written back to the disk, this is an incredibly fast and space-efficient way to inspect large archived server logs.

Basic Usage: Reading a Compressed File

To view the contents of a bzip2 archive, simply type the command followed by the filename.

bzcat auth_logs_archive.bz2

The command will instantly print the uncompressed text to your screen. If the file is a massive log file (which is highly likely, since it was large enough to require compression), the text will fly past your screen uncontrollably. To make it readable, you should always pipe the output of bzcat into a pager utility like less:

bzcat auth_logs_archive.bz2 | less

Now, the uncompressed data will pause at the end of the first page. You can use the arrow keys to scroll through the log file at your own pace. Press q to exit the pager.

Searching a Compressed File

Because bzcat streams the uncompressed data to standard output, you can pipe that stream directly into other powerful Linux text processing tools. For example, if you need to search a massive compressed log archive for a specific IP address, you can pipe the output into grep:

bzcat auth_logs_archive.bz2 | grep "192.168.1.50"

This command extracts the data in memory and instantly searches it, printing only the lines containing that specific IP address, all without ever creating a temporary text file on your drive.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.