LinuxCommandLibrary

gzcmp

Compare two compressed files

SYNOPSIS

gzcmp [cmp_options] file1 [file2]

PARAMETERS

-l, --verbose
    Output decimal byte numbers and differing byte values

-s, --quiet, --silent
    Suppress output; use exit status only (0 identical, 1 differ, 2 error)

-i SKIP, --ignore-initial=SKIP
    Skip first SKIP bytes in both inputs

-i SKIP1:SKIP2
    Skip SKIP1 bytes in file1, SKIP2 in file2

-b, --print-bytes
    Print only differing bytes (octal)

-n LIMIT, --bytes=LIMIT
    Compare at most LIMIT bytes

--help
    Display usage summary

--version
    Print version info

DESCRIPTION

gzcmp is a wrapper script from the gzip package that compares files by decompressing them on the fly if compressed (.gz). It pipes decompressed data through gzip -cd to cmp, enabling transparent handling of compressed files without manual extraction. Invoke with one or two filenames. If only one file is given, it compares to the .gz version of the same basename (e.g., gzcmp foo compares foo to foo.gz). Supports multiple compression suffixes like .gz, .z. Byte positions and differences refer to uncompressed content. Efficient for verifying backups or logs, as no temporary files are created—uses pipes. Exit status mirrors cmp: 0 (identical), 1 (differ), 2 (error). Ideal for scripts checking archive integrity. Handles uncompressed files directly, passing to cmp. Part of standard gzip tools on Linux/Unix systems.

CAVEATS

Compares uncompressed content only; identical content may have different compressed sizes.
Errors if files are invalid gzip streams or unreadable.
Does not handle concatenated/multi-member gzip archives properly.

BEHAVIOR WITH ONE FILE

If only file1 given, compares to file1.gz (or equivalent suffix)

EXAMPLES

gzcmp -s foo.gz bar.gz
Quietly check if identical.
gzcmp -l archive1.tar.gz archive2.tar.gz
List differing bytes

HISTORY

Part of gzip since 1992 release by Jean-loup Gailly. Evolved with GNU gzip; gzcmp often hard-linked to zcmp. Maintained for compatibility in Linux distros.

SEE ALSO

cmp(1), gzip(1), zcat(1), zdiff(1)

Copied to clipboard