How to Read Compressed lzma Files Using the lzless Command in Linux

When you compress a massive log file using the legacy lzma utility, the resulting file is encoded in a highly compressed binary format. If you try to open it with standard text viewing tools like cat or less, your terminal screen will instantly fill with unreadable, corrupted characters. While you could decompress the entire file back into a massive text document just to read it, doing so wastes time and hard drive space. Instead, you can use the lzless command to read the compressed data seamlessly.

How the lzless Command Works

The lzless utility acts as a specialized bridge between the lzma decompression algorithm and the standard less terminal pager. When you run it against a compressed file, it decompresses the data directly into your computer’s RAM, rather than writing it to the hard drive, and immediately pipes that readable text to your screen.

To read a compressed log file named server_logs.txt.lzma, simply run:

lzless server_logs.txt.lzma

Navigating the Pager Interface

Because the output is routed through the standard less pager, you get access to all of its powerful navigation tools. This is the primary advantage of lzless over its older, heavily restricted sister command, lzmore.

Once the file opens in your terminal, you can navigate the text using these keyboard shortcuts:

  • Arrow Keys: Use the Up and Down arrow keys to scroll through the text one line at a time, in both directions. This is a crucial feature that lzmore lacks.
  • Spacebar: Press the Spacebar to jump forward exactly one full page (or screen) of text.
  • b: Press the ‘b’ key to jump backward exactly one full page.
  • g and G: Press the lowercase ‘g’ key to jump instantly to the very top (beginning) of the document. Press the uppercase ‘G’ (Shift + g) to jump to the very bottom (end) of the document.

Searching for Text Inside Compressed Files

Perhaps the most powerful feature of the lzless interface is its ability to perform deep keyword searches on the data while it is still technically compressed on your hard drive.

  1. While viewing the file in lzless, type a forward slash (/). This will open a small search prompt at the bottom left corner of your terminal.
  2. Type the word you are looking for (e.g., /error 500) and press Enter.
  3. The pager will instantly jump to the first occurrence of that phrase and highlight it.
  4. To jump to the next occurrence of the phrase, simply press the lowercase n key. To jump to the previous occurrence (searching backward through the document), press the uppercase N key.

Once you are finished reading and searching, press the q key to quit the pager and return to your standard bash prompt. The original .lzma file remains perfectly compressed and untouched on your drive.

Get the best tech tips delivered straight to your inbox.

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