Say I've got two binary files, each roughly 50MB, that may contain a digitally-identical portion. Is there an easy way to compare these two files, find the longest identical portion, and save that to a file?

(If it matters, the files in question are stream-capture AAC files. They've got some audio boilerplate that sounds identical, but it may or may not be digitally identical. So I've got a two part task: first determine if the boilerplate is digitally identical, second extract the identical portion.)

  • rsync has at its core a clever technique to locate same and ":changed" regions of two usually large files using only small information from one of them, accessed across a potentially costly network, see en.wikipedia.org/wiki/Rsync#Algorithm . The program has accreted options to manage syncing whole trees of files across many kinds of transports and platforms, but you might be able to extract the core algorithm and use it. Or go back to Tridgell's original work and build forward. Sep 29, 2015 at 7:08

1 Answer 1


I recommend you to use cmp it is quite useful and got nice options like -b if you want to print bytes that differ and -l to be more verbose. For instance to compare a and b file use a command line like:

$ cmp -lb a b

It will output you all bytes that differ. If both file are the same, cmp will quietly return (you can always check its return value $? ) Note that cmp with -b option will output only bytes that differ and that if you do not use -l option, it will stop on the first byte that differ.

  • cmp will only help find matching portions that start at the same offset in both files. Sep 27, 2015 at 21:41
  • 1
    Offset of the potentially matching bytes are definitely not going to be the same, so I guess that means that cmp is out.
    – mikeola
    Sep 28, 2015 at 0:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .