LinuxCommandLibrary

lzcat

Decompress and concatenate compressed files to standard output

TLDR

View documentation for the original command

$ tldr xz
copy

SYNOPSIS


lzcat [OPTION]... [FILE]...


Example:

lzcat document.xz
lzcat archive.lzma > output.txt
ls -l /var/log/ | lzcat - (for a compressed stream from stdin)

PARAMETERS

FILE
    The path to the .xz or .lzma compressed file(s) to decompress. If no file is specified, or if FILE is `-`, `lzcat` reads from standard input.

-d, --decompress, --uncompress
    These options are implied by `lzcat` and explicitly decompress the input file(s).

-k, --keep
    Do not delete input files after successful decompression. By default, the original compressed file is removed.

-f, --force
    Force decompression, even if the output file already exists, or if there are multiple hard links to the input file, or if there are read or write errors.

-c, --stdout, --to-stdout
    Write output to standard output. This is the default and primary behavior of `lzcat`.

-q, --quiet
    Suppress all warnings and error messages.

-v, --verbose
    Display verbose information (e.g., compression ratio, file names) during processing.

-S SUFFIX, --suffix=SUFFIX
    Specify the suffix of compressed files. The default suffix is `.xz` or `.lzma`.

-h, --help
    Display a help message and exit.

-V, --version
    Display version information and exit.

DESCRIPTION

lzcat is a command-line utility used to decompress files compressed with the LZMA or XZ compression algorithms and print their uncompressed content to standard output (stdout). It functions similarly to the standard `cat` command, but for compressed data. It is typically a symbolic link to `xzcat` or directly to the `xz` executable with the decompression (`-d`) and output to stdout (`-c`) flags implicitly set.

This makes it convenient for quickly viewing the content of a compressed file without explicitly decompressing it to disk, or for piping its uncompressed output to other commands for further processing. For instance, `lzcat file.xz | grep "pattern"` allows searching within a compressed file without extracting it first. It only performs decompression; it cannot be used for compression.

CAVEATS

  • `lzcat` is typically a symbolic link or a script wrapper for `xz -d -c`. Its behavior is therefore largely governed by the underlying `xz` utility.
  • It only handles decompression; it cannot compress files.
  • It primarily outputs to standard output. If you want to save the decompressed content to a file, you must redirect the output (e.g., `lzcat file.xz > output.txt`).
  • It expects `.xz` or `.lzma` file formats. It will not work for `.gz`, `.bz2`, or other compressed file types.

<I>USAGE EXAMPLES</I>

  • `lzcat document.xz`: Decompress `document.xz` and print its content to the terminal.
  • `lzcat access.log.xz | less`: View the content of a compressed log file page by page.
  • `lzcat old_data.tar.lzma > new_data.tar`: Decompress `old_data.tar.lzma` and save the uncompressed tar archive as `new_data.tar`.
  • `curl example.com/file.xz | lzcat`: Download a compressed file from the internet and decompress it on-the-fly, printing to stdout.
  • `lzcat -k myfile.xz`: Decompress `myfile.xz` to stdout, but keep the original `myfile.xz` file.

<I>EXIT STATUS</I>

  • `0`: Success.
  • `1`: An error occurred.
  • `2`: Something went wrong with the input file(s).

HISTORY

The `lzcat` command is part of the `xz` utilities, which were developed to provide superior compression ratios compared to older tools like `gzip` and `bzip2`. `xz` and the underlying LZMA2 compression format gained prominence in the Linux ecosystem, becoming the default compression for many package managers and archives (e.g., `.tar.xz` archives). `lzcat` (and `xzcat`) was introduced to provide a familiar `cat`-like interface for viewing these modern compressed files, mirroring the functionality of `zcat` and `bzcat` for their respective formats. Development of the `xz` tools began around 2005-2006.

SEE ALSO

xz(1), xzcat(1), lzma(1), cat(1), gzip(1), zcat(1), bzip2(1), bzcat(1)

Copied to clipboard