Linux: diff, Compare Files

By Xah Lee. Date: . Last updated: .

Compare Binary Files

cmp file1 file2
If 2 files have same content, there is no output. Else it'll print the first byte count that's different.

Sample output:

file1 file2 differ: byte 174, line 4

Find Difference Between 2 Text Files

diff file1 file2
show difference between text files.

Most useful options of diff:

  • -i or --ignore-case
  • -E or --ignore-tab-expansion
  • -b or --ignore-space-change
  • -w or --ignore-all-space
  • -B or --ignore-blank-lines
  • --strip-trailing-cr

Linux, diff