A compact guide to using the cmp command for exact file comparisons. 01.03.2026 | reading time: 2 min When you need to know whether two files are exactly the same, cmp will tell you by comparing them byte-by-byte; it prints the first difference or stays silent for identical files. See it in action ```$ printf '\x01\x02\x03' > file1.bin\n$ printf '\x01\x02\x04' > file2.bin\n$ cmp file1.bin file2.bin\nfile1.bin file2.bin differ: byte 3, line 1\n$ cmp -s file1.bin file1.bin; echo $?\n0\n$ cmp -s file1.bin file2.bin; echo $?\n1\n$ cmp -l file1.bin file2.bin\n3 3 4\n``` Options that matter Use -s to run a quiet check and rely on the exit code, -l to list every differing byte, -i to skip a number of initial bytes, and -n to limit how many bytes are compared; these options let you craft fast, script-friendly checks. Where cmp shines Prefer cmp for binary files and automated tests where a simple same-or-different answer is enough, or when you need the exact byte offset of the first mismatch to debug corrupt data or protocol issues. Other commands nearby For line-oriented differences use diff, for checksum-based verification use sha256sum or md5sum, and for efficient file synchronization use rsync; each tool solves a slightly different problem in the comparison toolbox. Next steps Try integrating cmp -s into scripts and pre-copy checks, and then deepen your Linux skills with formal study; consider CompTIA Linux+ or LPIC-1 exam preparation, for which bitsandbytes.academy offers intensive courses to accelerate learning. Join Bits & Bytes Academy First class LINUX exam preparation. utilities filesystem troubleshooting scripting backup