zdiff
Compare compressed files line by line
TLDR
Compare two files, uncompressing them if necessary
Compare a file to a gzip archive with the same name
SYNOPSIS
zdiff [diff_options] file1 [file2]
zdiff [diff_options] -- file1 file2
PARAMETERS
diff_options
Any option accepted by the standard diff command. zdiff passes these options directly. Examples include:
-u: Output in unified context format.
-c: Output in context format.
-N: Treat absent files as empty.
-q: Report only whether files differ, not the details.
-i: Ignore changes in white space at line end.
file1
The path to the first compressed file to compare. If file2 is omitted, zdiff compares file1 with standard input.
file2
The path to the second compressed file to compare. If omitted, file1 is compared with standard input.
DESCRIPTION
zdiff is a utility designed to compare the content of compressed files by transparently decompressing them on-the-fly and feeding their output to the standard diff command. It supports files compressed with common utilities like gzip (.gz), compress (.Z), bzip2 (.bz2), lzma (.lzma), xz (.xz), and zstd (.zst, if available). By acting as a wrapper, zdiff eliminates the need for manual decompression before comparing files, streamlining workflows for users dealing with archived data. All options provided on the command line are directly passed to the underlying diff command, allowing users to leverage diff's extensive comparison capabilities.
CAVEATS
Requires the diff command to be installed and accessible in the system's PATH.
Appropriate decompression utilities (e.g., gzip, bzip2, xz, zstd) must be installed for zdiff to handle corresponding compressed file types.
On-the-fly decompression can introduce a performance overhead compared to comparing uncompressed files directly.
Memory usage might be higher as files are decompressed in memory or to temporary locations.
EXIT STATUS
zdiff returns the exit status of the underlying diff command:
0: No differences were found between the files.
1: Differences were found.
2: An error occurred (e.g., file not found, permission denied).
HISTORY
zdiff is part of the gzip package, which was initially developed by Jean-loup Gailly and Mark Adler. It emerged as a practical wrapper for diff, addressing the growing need to compare large text files that were increasingly being stored in compressed formats to save disk space and expedite transfers. Its design as a simple front-end to diff allowed it to leverage diff's robust comparison algorithms while transparently handling decompression, making it a staple utility in environments where compressed data is common.