LinuxCommandLibrary

xzdiff

Show differences between compressed files

TLDR

Compare two files

$ xzdiff [path/to/file1] [path/to/file2]
copy

Compare two files, showing the differences side by side
$ xzdiff --side-by-side [path/to/file1] [path/to/file2]
copy

Compare two files and report only that they differ (no details on what is different)
$ xzdiff --brief [path/to/file1] [path/to/file2]
copy

Compare two files and report when the files are the same
$ xzdiff --report-identical-files [path/to/file1] [path/to/file2]
copy

Compare two files using paginated results
$ xzdiff --paginate [path/to/file1] [path/to/file2]
copy

SYNOPSIS

xzdiff [diff_options] file1 [file2]

PARAMETERS

[diff_options]
    Any options understood by the diff command. xzdiff passes these directly to the underlying diff process.

file1
    The path to the first file to compare. This can be an xz compressed file (e.g., file.txt.xz) or a regular uncompressed file.

file2
    The path to the second file to compare. This can also be an xz compressed file or a regular uncompressed file. If file2 is omitted, file1 is compared with standard input.

DESCRIPTION

xzdiff is a convenience script that allows users to compare two files using the standard diff utility, where one or both of the files may be compressed with XZ compression. It acts as a wrapper, automatically decompressing the files on-the-fly before piping their content to diff. This eliminates the need for manual decompression, temporary file creation, and subsequent deletion, simplifying the comparison of compressed data.

It behaves exactly like diff, passing all command-line arguments directly to the underlying diff command after handling the decompression. This makes it particularly useful for quickly comparing compressed log files, configuration archives, or any data stored in the .xz format without explicit prior decompression steps.

CAVEATS

Dependency: xzdiff relies on the diff and xzcat (or xz) utilities being available in the system's PATH. If they are missing, the command will fail.

Performance: While convenient, the on-the-fly decompression adds processing overhead. For extremely large files, manually decompressing the files first and then running diff might be marginally faster in some scenarios, though less convenient.

Error Handling: If an input file is corrupted or not a valid xz file, xzcat will report an error, which xzdiff will propagate.

ENVIRONMENT VARIABLES

xzdiff may be influenced by environment variables that affect its underlying commands. For instance, the DIFF environment variable can be used to specify an alternative diff command to execute instead of the default.

EXIT STATUS

The exit status of xzdiff is typically the exit status of the diff command it invokes:
0: Files are identical.
1: Files differ.
2: An error occurred (e.g., cannot access a file, invalid options).

HISTORY

xzdiff is an integral part of the xz-utils package, which provides command-line tools for compressing and decompressing files using the LZMA2 algorithm in the XZ container format. Developed to offer superior compression ratios compared to older formats like Gzip and Bzip2, the xz utilities, including xzdiff, have become standard on many Linux distributions, reflecting the widespread adoption of the xz format for archiving, software distribution, and system logs.

SEE ALSO

diff(1), xz(1), xzcat(1), zdiff(1), bzdiff(1)

Copied to clipboard