I would love some help with a Bash script loop that will show all the differences between two binary files, using just
cmp file1 file2
It only shows the first change I would like to use cmp because it gives a offset an a line number of where each change is but if you think there's a better command I'm open to it :) thanks
Use the command cmp to check if two files are the same byte by byte. The command cmp does not list differences like the diff command. However it is handy for a fast check of whether two files are the same or not (especially useful for binary data files).
You can also force diff to consider all files to be binary files, and report only whether they differ (but not how). Use the `--brief' option for this. In operating systems that distinguish between text and binary files, diff normally reads and writes all data as text.
If you want to compare two files byte by byte, you can use the cmp program with the --verbose ( -l ) option to show the values of each differing byte in the two files. With GNU cmp , you can also use the -b or --print-bytes option to show the ASCII representation of those bytes. See Invoking cmp , for more information.
I think cmp -l file1 file2
might do what you want. From the manpage:
-l --verbose Output byte numbers and values of all differing bytes.
The output is a table of the offset, the byte value in file1 and the value in file2 for all differing bytes. It looks like this:
4531 66 63 4532 63 65 4533 64 67 4580 72 40 4581 40 55 [...]
So the first difference is at offset 4531, where file1's decimal octal byte value is 66 and file2's is 63.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With