How to Use the bzless Command to View Compressed Files in Linux

When you use the bzcat command to read a compressed bzip2 archive, the uncompressed text is instantly dumped directly onto your terminal screen. If the archive contains a massive server log file spanning thousands of lines, the text will scroll past your eyes in a dizzying blur, making it impossible to actually read the data. While you can pipe the output into a pager utility like less (e.g., bzcat file.bz2 | less), Linux provides a much cleaner, dedicated command for this exact task: bzless.

How bzless Works

The bzless command is a dedicated viewer specifically built to handle .bz2 files. It acts as an all-in-one combination of a decompression engine and a text pager. When you run bzless against an archive, it temporarily uncompresses the data into your system’s RAM (meaning it never wastes hard drive space) and immediately pauses the output at the very end of the first page. It allows you to comfortably scroll through massive compressed log files exactly as if they were standard text files.

Basic Usage and Navigation

To view a compressed file with a paused, scrollable interface, simply type the command followed by the filename.

bzless apache_error_log.bz2

The screen will fill with the first page of uncompressed text. Because bzless uses the standard less pager under the hood, you can navigate through the data using familiar keyboard shortcuts:

  • Down Arrow or Enter: Scroll down one line at a time.
  • Up Arrow: Scroll up one line at a time.
  • Spacebar: Jump forward an entire page.
  • b key: Jump backward an entire page.
  • q key: Quit the viewer and return to the normal terminal prompt.

Searching Within the Compressed File

One of the most powerful features of bzless is its interactive search capability. While you are viewing the uncompressed file on the screen, you can search for specific error codes or IP addresses.

  1. While inside the bzless viewer, press the forward slash (/) key.
  2. A prompt will appear at the bottom-left corner of the screen.
  3. Type the word or IP address you are looking for (e.g., /Failed password) and press Enter.

The viewer will instantly jump to the first occurrence of that phrase and highlight it on the screen. If you want to find the next occurrence of the same phrase further down in the file, simply press the n key (for next). To search backward towards the top of the file, press N (Shift+N).

Get the best tech tips delivered straight to your inbox.

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