zless
View compressed text files
TLDR
Page through a gzip compressed file with less
SYNOPSIS
zless [less_options] [file ...]
PARAMETERS
[less_options]
Any options understood by the less command. zless passes these options directly to less without processing them itself. For a full list, refer to the less(1) man page.
[file ...]
One or more paths to compressed or uncompressed files to be viewed. zless will automatically decompress recognized formats. If no file is specified, zless will read from standard input.
DESCRIPTION
The zless command is a utility that allows users to view the contents of compressed files using the familiar interface of the less pager. It acts as a wrapper, automatically detecting the compression type (e.g., Gzip, Bzip2, XZ, Zip) and decompressing the file on the fly before piping its content to less. This eliminates the need for manual decompression, making it highly convenient for quickly inspecting log files, archives, or other compressed data without modifying the original file. It supports multiple compressed files as input, displaying them sequentially.
CAVEATS
Dependency: Requires the less pager and appropriate decompression utilities (e.g., gzip, bzip2, xz, unzip) to be installed and accessible in the system's PATH.
Performance: Viewing very large compressed files can be slow due to the on-the-fly decompression process, especially on systems with limited CPU or I/O resources.
Temporary Files: Some implementations or scenarios might create temporary files during decompression, though often it's done via pipes.
Unsupported Formats: Will fail to display files compressed with unrecognized or unsupported algorithms.
HOW IT WORKS
zless typically operates by chaining commands via pipes. When invoked, it determines the compression type of the input file and then invokes the corresponding decompression utility (e.g., gunzip, bunzip2, unxz) to decompress the file's content to standard output. This decompressed stream is then piped directly to the standard input of the less command. All options and arguments (except for those specifically indicating compressed file paths) provided to zless are generally passed through to less.
ENVIRONMENT VARIABLES
The behavior of zless is heavily influenced by environment variables that affect less. Specifically, the LESS environment variable can be used to pass default command-line options to less automatically every time it is invoked by zless.
HISTORY
The zless command emerged as a companion to the gzip (or similar compression) utilities, mirroring the functionality of older commands like zmore. As less gained popularity as the preferred pager over more due to its advanced features (like backward navigation and search), zless was developed to provide the same seamless experience for compressed files, integrating the decompression step directly into the viewing workflow. It's often distributed as part of the gzip package or as a standalone script.