Skip to content

diff | Cheatsheet

Display the differences between two files, or each corresponding file in two directories. Each set of differences is called a "diff" or "patch". For files that are identical, diff normally produces no output; for binary (non-text) files, diff normally reports only that they are different.


This will print the offset and bytes in hex:

cmp -l file1.bin file2.bin \
    |gawk '{printf "%08X %02X %02X\n", $1, strtonum(0$2), strtonum(0$3)}'

Or do $1-1 to have the first printed offset start at 0.

cmp -l file1.bin file2.bin \
    |gawk '{printf "%08X %02X %02X\n", $1-1, strtonum(0$2), strtonum(0$3)}'

diff + xxd

diff -y <(xxd foo1.bin) <(xxd foo2.bin)

colordiff + xxd

colordiff -y <(xxd foo1.bin) <(xxd foo2.bin)

Diff two files with diff + strings

diff -y <(strings device.cfg) <(strings device2.cfg)