HowTo: Compare binary files on Linux

Step-by-Step descriptions of how to do things.
Post Reply
User avatar
peter_b
Chatterbox
Posts: 378
Joined: Tue Nov 12, 2013 2:05 am

HowTo: Compare binary files on Linux

Post by peter_b »

If you use "diff" to compare binary files (that have the same size), it will just tell you that:
Binary files A and B differ
If you want to know the which bytes at which offsets differ, use the "cmp" command:

Code: Select all

$ cmp -l a.bin b.bin
Without the "-l" parameter, cmp will just tell you the first offset that differs.

With "-l" it will give you an output that looks somewhat like this:

Code: Select all

     173  50 362
    9067  63  67
    9068  70  60
    9069  65  62
According to cmp's manpage, it's "byte numbers and differing byte values".
The first column is the byte offset in decimal (CAUTION: starts at 1 not 0), but I haven't figured out yet what the values of column 2 or 3 mean. In my case here it's neither the value in each file, nor the difference, nor anything.

However: cmp is nice to see how many bytes at which offsets differ! :D
Post Reply