xzless
View xz-compressed files without uncompressing
TLDR
View a compressed file
View a compressed file and display line numbers
View a compressed file and quit if the entire file can be displayed on the first screen
SYNOPSIS
xzless [file...]
PARAMETERS
file...
One or more paths to .xz compressed files, or other file types that xzless can decompress and display. If no file is specified or file is '-', xzless reads from standard input.
DESCRIPTION
xzless is a command-line utility that allows users to view the contents of files compressed with the XZ compression algorithm (typically .xz files) directly in the less pager. It acts as a convenient wrapper, enabling interactive browsing of compressed data without the need to first decompress the entire file to a temporary location or to disk.
When invoked, xzless internally decompresses the input file using xz -dc (or xzcat) and pipes the resulting decompressed stream to the less command. This seamless integration means that users can navigate, search, and view large compressed files with all the familiar functionalities of less, such as scrolling, pattern searching, and jumping to specific lines. It is particularly useful for examining compressed log files, documentation, or archives efficiently, saving disk space and time. Its design follows the pattern of similar utilities like zless for Gzip files and bzless for Bzip2 files, providing a consistent user experience for various compressed formats.
CAVEATS
xzless relies on the xz and less utilities being installed and accessible in the system's PATH.
Performance can be marginally affected by on-the-fly decompression, especially with very large files or on systems with limited CPU resources.
Viewing extremely large files might consume more memory in the less buffer than viewing smaller files.
Corrupted .xz files will result in decompression errors and will not be displayed correctly.
HOW IT WORKS
xzless is a shell script that functions by creating a pipe. It executes xz -dc (or xzcat) to decompress the specified file(s) to standard output, and then pipes this decompressed data to the standard input of the less pager. The command chain typically looks like:
xz -dc [file] | less
This pipeline allows less to display the file content incrementally as it is decompressed, providing an efficient way to view even very large compressed files without requiring significant temporary disk space.
LESS OPTIONS AND ENVIRONMENT VARIABLES
While xzless itself doesn't have unique command-line options, it effectively supports all options available to the less pager, as it simply passes the decompressed stream to less. Options like -N (display line numbers), +F (follow end of file), -/pattern (search for pattern), etc., can be used. These options are usually passed directly after xzless and before the filename, or can be specified via the LESS environment variable (e.g., export LESS='-N -i').
The LESSOPEN environment variable can also be relevant; xzless often leverages LESSOPEN to register itself as a preprocessor for .xz files, allowing less to automatically invoke xzless when opening such files directly.
HISTORY
The xzless command is part of the xz utilities, a suite of tools for manipulating files compressed in the XZ format. The XZ format itself is a modern, high-compression data compression format based on the LZMA2 algorithm, designed as a successor to LZMA and often replacing older formats like Gzip and Bzip2 in many Linux distributions for package management and archiving.
xzless was developed following the established pattern of convenient wrappers like zless (for Gzip) and bzless (for Bzip2), aiming to provide a consistent and user-friendly way to interactively view compressed files without explicit decompression steps. Its development is tied to the evolution and adoption of the XZ compression standard.