Diffing binaries, in living color!
February 04, 2022 #linuxI recently needed to compare two binary files (ISO images) in order to debug why one ISO would boot with legacy BIOS and the other wouldn't, even though they were presumably generated by the same tooling (turns out they weren't exactly, but that's not what this post is about.)
This post is about a quick way to generate a binary diff, with color, which
really helps with visually seeing differences in a sea of hex. Using
colordiff and xdd
, it's easy!
colordiff -y <(xxd a.iso) <(xxd b.iso)|less -R
Where the output looks something like:
For large binary files, you can use the -l
option to xxd
to limit length,
e.g. xxd -l 1000 foo.bin
. The -R
option to less tells it to output control
characters, which is what colordiff
uses for coloring output. If you don't
include that option, you get this disaster instead: