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.

LinuxdiffcmpFilesLow risk
Run cmp file1.bin file2.bin — no output means identical; add -l to list every differing byte offset.

01Command

Command
$ cmp -l file1.bin file2.bin

02What 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

RiskLow risk

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • cmp(1) — man7.org
    man7.org · community · 2026-09-17
    Evidence: Man page documents cmp comparing two files byte by byte, with -l listing all differing byte values and -s staying silent
  • cmp(1) — Ubuntu manpage
    Ubuntu · community · 2026-09-17
    Evidence: 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