zcmp
Compare compressed files
TLDR
Invoke cmp on two files compressed via gzip
Compare a file to its gzipped version (assuming .gz exists already)
SYNOPSIS
zcmp [ cmp_options ] file1 [ file2 ]
PARAMETERS
cmp_options
Any valid option supported by the underlying cmp command. zcmp passes these options directly to cmp. Common options include:
-l, --verbose
For each difference, print the byte number (decimal) and the differing byte values (octal) for both files.
-s, --quiet, --silent
Suppress all output. Only the exit status indicates whether the files differ.
-n BYTES, --bytes=BYTES
Compare only the first BYTES bytes of the files.
file1
The path to the first file to compare. This file can be compressed (e.g., file.txt.gz) or uncompressed.
file2
The path to the second file to compare. This file can also be compressed or uncompressed. If file2 is omitted, zcmp (and the underlying cmp) will generally return an error, as cmp requires two files for comparison.
DESCRIPTION
The zcmp command serves as a convenient wrapper around the standard cmp utility, specifically designed for comparing files that are compressed. It automatically decompresses the specified files on-the-fly using appropriate tools like gzip, bzip2, or xz, and then pipes their uncompressed content to cmp for byte-by-byte comparison.
This allows users to compare compressed archives without needing to manually decompress them first, simplifying workflows when dealing with large datasets or system backups. zcmp essentially extends the functionality of cmp to compressed data, providing the same comparison logic and output formats. It supports various common compression formats, allowing for seamless comparison regardless of the underlying compression method.
CAVEATS
Performance Overhead: Decompressing files on-the-fly introduces a performance overhead compared to comparing uncompressed files directly. This can be significant for very large files or slow CPUs.
Temporary Files: While modern implementations often stream content, older versions or specific configurations might create temporary uncompressed files, potentially consuming disk space and increasing I/O.
Error Handling: Errors can originate from either the decompression utility (e.g., corrupted archive, unsupported format) or the cmp command itself (e.g., permission issues, non-existent files). zcmp's error messages will reflect the source of the problem.
Limited Unique Options: zcmp itself doesn't add many unique options beyond handling compressed input; its power comes from leveraging cmp's options with compressed data.
EXIT STATUS
zcmp returns an exit status indicating the comparison result, consistent with cmp:
0: The files are identical.
1: The files differ.
2: An error occurred (e.g., inaccessible file, invalid arguments, decompression failure).
HISTORY
The zcmp command is typically distributed as part of the gzip package or similar compression utilities on Linux and Unix-like systems. It emerged as a practical utility to streamline operations on compressed files, mirroring the existing cmp functionality without requiring manual decompression steps. Its development has focused on providing a transparent wrapper that intelligently handles various compression formats supported by the underlying system's decompression tools, making it a staple for system administrators and users working with compressed data.