LinuxCommandLibrary

lzcmp

Compare compressed files without decompressing

TLDR

View documentation for the original command

$ tldr xzcmp
copy

SYNOPSIS

lzcmp [OPTIONS] FILE1 [FILE2]

PARAMETERS

FILE1
    The path to the first LZMA or XZ compressed file to compare.

[FILE2]
    The path to the second LZMA or XZ compressed file to compare. If omitted, the behavior might vary or result in an error depending on the underlying `cmp` implementation, as `cmp` typically requires two files for comparison.

[CMP_OPTIONS]
    Options to be passed directly to the underlying cmp utility. These options, such as -s (silent mode) or -l (detailed byte-by-byte listing), control the comparison behavior itself. They are typically placed before or after the filenames depending on the specific `cmp` implementation and context.

[XZ_OPTIONS]
    Options specific to the xz or lzma decompression utility. These options, such as -q (quiet mode during decompression), typically need to be placed before the filenames. They control the decompression process itself and not the comparison.

DESCRIPTION

The lzcmp command is a utility designed to compare two LZMA or XZ compressed files without the need for manual decompression. It acts as a shell script wrapper around the standard cmp command, leveraging the xz or lzma utilities to decompress the files on-the-fly via pipes. This allows for efficient byte-by-byte comparison of large compressed archives, saving disk space and avoiding the creation of temporary uncompressed files.

When invoked, lzcmp pipes the decompressed content of each specified file to cmp, which then performs the comparison. By default, it uses cmp to determine if the files are identical or where the first difference occurs. If the files are identical, lzcmp exits with a status of 0. If they differ, it exits with a non-zero status.

While primarily designed for `cmp` functionality, similar tools like `lzdiff` (or `xzdiff`) exist for `diff`-style comparisons. lzcmp is part of the `xz` utilities package, which supersedes the older `lzma` utilities, providing robust compression and decompression capabilities.

CAVEATS

  • Dependency: lzcmp relies on the presence of the `cmp` utility and either `xz` or `lzma` for decompression. Without these, it cannot function.
  • Performance: Comparing large compressed files can still be CPU and I/O intensive due to the on-the-fly decompression.
  • Error Handling: Errors during decompression (e.g., corrupt archives) or comparison (e.g., permission issues) will result in a non-zero exit status, often greater than 1.
  • Wrapper Nature: As a shell script wrapper, its exact behavior and supported options can sometimes depend on the specific implementation of the script on your system, or the versions of `cmp` and `xz`/`lzma` installed.

EXIT STATUS

The exit status of lzcmp primarily reflects the exit status of the underlying cmp command:
0: The files are identical.
1: The files differ.
>1: An error occurred (e.g., invalid arguments, input/output error, or cannot open a file).

ENVIRONMENT VARIABLES

lzcmp respects the following environment variables, which can override the default comparator program:
CMP: Specifies the path to the `cmp` utility to be used instead of the default `/usr/bin/cmp`.
DIFF: While lzcmp primarily uses `cmp`, this variable is relevant for its `lzdiff` (or `xzdiff`) counterpart, allowing specification of the `diff` utility to use.

HISTORY

The lzcmp command is part of the `xz` utilities, which are the modern successor to the `lzma` utilities. Its development lineage traces back to the need for efficient handling of compressed files in Unix-like systems. Before such wrappers, users would manually decompress files to temporary locations, compare them, and then delete the temporary files. This was cumbersome and inefficient. The creation of `lzcmp` (and its counterparts like `xzcmp` and `lzdiff`) streamlined this process by transparently piping decompressed content to comparison tools, making it a staple for developers and system administrators working with compressed data. It embodies the Unix philosophy of combining small, specialized tools (like `cmp` and `xz`) to achieve a more complex task.

SEE ALSO

cmp(1), diff(1), xz(1), lzma(1), xzcmp(1), xzdiff(1)

Copied to clipboard