LinuxCommandLibrary

zstdless

View compressed files without extracting them

TLDR

Open a zstd compressed file

$ zstdless [path/to/file.zst]
copy

SYNOPSIS

zstdless [less_options] [file...]
command | zstdless [less_options]

PARAMETERS

file...
    One or more paths to Zstandard compressed files (e.g., ending in .zst) to be viewed. If no file is specified, zstdless reads from standard input.

less_options
    zstdless typically passes any options it receives directly to the underlying less pager. Common examples include:
-i: Ignore case in searches.
-N or --LINE-NUMBERS: Display line numbers.
-S: Chop long lines (don't wrap).
-P prompt: Set the prompt string.
+G: Go to the end of the file on startup.
+number: Start at the specified line number.
+pattern: Start at the first occurrence of the specified pattern.

DESCRIPTION

zstdless is a utility that allows users to view the contents of files compressed with the Zstandard (ZSTD) compression algorithm without manually decompressing them first. It acts as a convenient wrapper, typically executing zstdcat (or zstd -d -c) to decompress the input file on the fly and then piping the decompressed output directly to the less pager. This enables interactive browsing, searching, and navigation within large compressed text files, similar to how one would use less on an uncompressed file. It's particularly useful for examining log files, documentation, or any text-based data that has been efficiently stored using ZSTD compression, saving disk space and simplifying the viewing process. Users don't need to worry about creating temporary decompressed files.

CAVEATS

Requires zstd and less to be installed on the system.
Primarily designed for viewing text-based ZSTD compressed files. While it might attempt to decompress any .zst file, the output will only be readable if it contains text.
Performance can be affected by CPU load for very large files, as decompression occurs on the fly.
If the input file is corrupted or not a valid ZSTD archive, zstdless (via zstdcat) will report an error, and less will display an empty or error stream.

IMPLEMENTATION

zstdless is typically implemented as a simple shell script, often resembling exec zstdcat "$@" | less. This pipes the decompressed output from zstdcat directly to less. In some environments, zstdless might be a symbolic link to less itself, relying on less's internal configuration (via LESSOPEN and LESSPIPE environment variables) to automatically detect and decompress ZSTD files before displaying them.

AUTOMATIC DECOMPRESSION WITH LESSOPEN

The less pager can be configured to automatically handle compressed files without needing a specific wrapper like zstdless. This is achieved using the LESSOPEN and LESSPIPE environment variables. If LESSOPEN is set to a command that can decompress a .zst file and output it, less will automatically decompress the file when it is opened. For example, a common LESSOPEN script would check the file extension and pipe it through the appropriate `*cat` utility (like zstdcat) if a match is found.

HISTORY

zstdless emerged as a natural extension of the *-less family of commands (like zless, bzless, xzless) following the increasing adoption of the Zstandard compression algorithm. While zstd itself was developed by Facebook and released in 2016, wrapper scripts like zstdless were created by the community or included in distributions to provide a convenient way to interact with .zst files, leveraging the familiar interface of the less pager. Its development reflects the need for on-the-fly decompression and viewing for newer, more efficient compression formats.

SEE ALSO

zstd(1), zstdcat(1), less(1), zless(1), bzless(1), xzless(1)

Copied to clipboard