Compare Binary Files Byte by Byte with cmp
Use cmp instead of diff when files are binary — it tells you if they differ and at which byte.
01Command
$ cmp -l file1.bin file2.bin02What it does
cmp compares two files byte by byte and, unlike diff, works correctly on binary data such as images, executables or downloads. Without flags it prints only the position of the first difference and exits, which makes it the quickest identity check; with -l it prints the byte number and the two values for every difference. A zero exit status means the files are identical, which is handy in shell scripts.
03Risk
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- cmp(1) — man7.orgEvidence: Man page documents cmp comparing two files byte by byte, with -l listing all differing byte values and -s staying silent
- cmp(1) — Ubuntu manpageEvidence: Ubuntu manpage shows cmp compares two files byte by byte and reports the offset where they differ; --bytes limits the comparison
Last verified: 2026-09-19 · Category: Files & Folders
06Related solutions
Find every occurrence of a pattern across all files in a tree, printed as file:line:number matches.
Unpack a gzipped tarball into the current directory while printing each file as it is extracted.
Show total, used, and available space plus usage percentage for every mounted filesystem in human-readable units.