LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

cmp

byte-by-byte file comparison

TLDR

Compare two files
$ cmp [file1] [file2]
copy
Silent comparison (exit code only)
$ cmp -s [file1] [file2]
copy
Show all differences
$ cmp -l [file1] [file2]
copy
Print differing bytes
$ cmp -b [file1] [file2]
copy
Compare first N bytes
$ cmp -n [1024] [file1] [file2]
copy
Skip bytes at start
$ cmp -i [100] [file1] [file2]
copy

SYNOPSIS

cmp [option]... file1 [file2 [skip1 [skip2]]]

DESCRIPTION

cmp compares two files byte by byte and reports the location of the first difference. By default, it prints the byte number and line number where the files diverge, or produces no output if they are identical.Unlike diff, which operates on text lines, cmp works at the byte level, making it more efficient and appropriate for binary files. The -s (silent) mode is commonly used in scripts where only the exit status matters: 0 for identical files, 1 for differences, and 2 for errors.The -l option lists all byte positions where the files differ, along with the differing byte values in octal. The tool can also skip initial bytes in one or both files and limit the comparison to a specified number of bytes.

PARAMETERS

-b, --print-bytes

Print differing bytes
-i skip, --ignore-initial skip
Skip first bytes of both files
-i skip1:skip2
Skip different amounts per file
-l, --verbose
Output all byte differences
-n limit, --bytes limit
Compare at most limit bytes
-s, --quiet, --silent
Suppress output, exit code only
--help
Display help
-v, --version
Show version

EXIT STATUS

0: Files are identical1: Files differ2: Error occurred

SKIP SUFFIXES

K (1024), M (1048576), G (1073741824)kB (1000), MB (1000000), GB (1000000000)

INSTALL

sudo apt install diffutils
copy
sudo dnf install diffutils
copy
sudo pacman -S diffutils
copy
sudo apk add diffutils
copy
sudo zypper install diffutils
copy
brew install diffutils
copy
nix profile install nixpkgs#diffutils
copy

CAVEATS

Cannot compare directories, only files. For text file differences, use diff instead. Reading from stdin use - as filename.

SEE ALSO

diff(1), comm(1), md5sum(1)

RESOURCES

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid