Overview
Inspecting rotated or archived system logs usually introduces unnecessary disk churn when archives must be decompressed before reading. The zless utility solves this bottleneck by providing immediate, full-featured terminal viewing directly on compressed files. In this guide, we explore practical techniques and core flags that streamline incident investigation while minimizing resource overhead on production servers.
Understanding zless and Preparing Sample Compressed Files
To configure an appropriate testing environment with necessary compression utilities, install the requisite packages via apt-get update -qq && apt-get install -y gzip util-linux.

Keep the exercise isolated from other projects by setting up a dedicated workspace using mkdir -p ~/zless_demo && cd ~/zless_demo.

Generate an initial mock application log containing typical server activities with printf 'Line 1: Server initialized\nLine 2: Connection received from 192.168.1.10\nLine 3: Processing API request: GET /items\nLine 4: Database query completed in 12ms\nLine 5: Response 200 OK sent\n' > app.log.

Create a compressed archive while retaining the uncompressed source file by running gzip -k app.log.

Verify the coexistence and respective sizes of both the plaintext log and its new .gz archive using ls -lh app.log*.

Navigating Compressed Files and Displaying Line Numbers
Ensure your terminal shell is operating within the demo directory by executing cd ~/zless_demo.

Behind the scenes, zless acts as a wrapper around the standard less pager, dynamically decompressing gzip streams in memory on the fly.
The file opens in an interactive terminal viewport, allowing smooth navigation using the arrow keys or Spacebar, while pressing q safely exits back to the shell prompt.

Passing the -N flag instructs the pager to prepend explicit line numbers alongside each output entry.
This capability proves invaluable during incident post-mortems when correlating stack traces or cross-referencing specific log positions with team members.

Inspecting Multiple Archives and Jumping Directly to Matches
Return to the practice folder before proceeding with multi-file inspections by running cd ~/zless_demo.

Simulate a secondary service log by executing printf 'Line 1: Worker process spawned\nLine 2: Warning: High memory utilization 84%%\nLine 3: Task completed\n' > worker.log.

Archive this second log file while keeping the raw file intact via gzip -k worker.log.

The command zless -p 'Warning' app.log.gz worker.log.gz loads multiple archives sequentially into the pager queue and automatically jumps the screen straight to the first occurrence matching the pattern ‘Warning’.
Within this viewing session, jump ahead to the next archive using :n or step backward to previous files using :p, enabling seamless traversal across batched rotation logs.

Plain Text Compatibility and Production Troubleshooting Tips
Switch once more to the sandbox directory by executing cd ~/zless_demo.

A major convenience of zless is its built-in fallback: standard uncompressed text files are handled just as effortlessly as archives.
Administrators can use identical muscle memory across mixed directories without checking file extensions or compression states beforehand.

When an interactive viewport is unnecessary and simple line matching will suffice, zcat app.log.gz | grep '200 OK' streams the decompressed output directly into the pipeline.
This approach extracts targeted log signatures immediately without leaving the active shell context.

After completing the tests, clean up the temporary directory and all generated sample files with rm -rf ~/zless_demo.

By mastering zless, system engineers and DevOps practitioners can dissect archived server telemetry rapidly while avoiding unnecessary decompression cycles and conserving local storage.