diffbin manual

diffbin does a byte-by-byte "diff" of two files which are not lines of text.

Example


$ diffbin myoldfile mynewfile


$ diffbin -context=20 myoldfile mynewfile


$ diffbin -context=20 -matchsize=20 -hexpos -ascii myoldfile mynewfile

Synopsis

diffbin [-matchsize=bytecount] [-context=bytecount] [-all] [-ascii] [-hexpos]
[-linelength=bytecount] oldfilename [newFileName|newDirName]

Description

diffbin does a byte-by-byte "diff" of two files which are not lines of text. For example, you could compare two executables and see the extra 7 bytes that are in one.

The output is in hexadecimal, showing you bytes that get added to and deleted from the "old" file to make the "new" file.

There is no known program analogous to patch that takes the output of diffbin and creates a copy of the new file from a copy of the old file. But there are several alternatives to diffbin listed on Freshmeat that are specifically designed to create such a patch file. These alternatives do not, however, produce output as useful as diffbin's for analyzing the difference between two files.

Output

Here's an example. In this example, we compared two files of about 250 bytes of ASCII. We used no diffbin options.
-      25: 6c7564

+      67: 65787472 61737475 666620

-     153: 74696d65 73

+     161: 67617262 616765

It says:

Here's an example with context. We used the option --context=4 on the same old and new files as the previous example.

       21: 23696e63 

-      25: 6c7564

       28: 65203c73 

       66: 75646520 

+      67: 65787472 61737475 666620

       70: 3c737464 

      149: 7379732f 

-     153: 74696d65 73

+     161: 67617262 616765

      158: 2e683e0a 

You see that diffbin has added lines showing 4 bytes on either side of each difference which are the same in both the old and the new files. For these common bytes, the offset is that in the old file. You have to figure out for yourself where the same bytes are in the new file.

The offset value on a deleted or same line (minus sign or no sign) is the offset in the old file. The offset value on an added line (plus sign) is the offset in the new file.

To avoid confusion in reading the offsets, just pretend the offsets with a plus sign before them aren't there. Then you have a simple picture of the old file, with new bytes stuck in between old ones.

Arguments

The two arguments identify the two files to compare. We arbitrarily call the first file the "old" file and the second one the "new file." you get the same comparison regardless of the order in which you specify the files. But if you think of one file as a modification to the other, you can save yourself some confusion reading this manual and the diffbin output by making that the "new" file.

The simplest way to specify the files is just to give file names for both. They can be absolute or relative file names (starting with slash or not).

Alternatively, for the new file, you can specify just the directory part of the file name and diffbin will assume the same final component os the old file. (For example, you specify /usr/src/oldprog/foo.c for the old file and /usr/src/newprog for the new file. That means the new file is /usr/src/newprog/foo.c.

Options

-linelength=bytecount
This option tells how many bytes of file contents diffbin puts on each line of output. This is not the number of characters in the output line; each byte takes 3 characters, and there is extra information on each line.

The default is 16.

-matchsize=bytecount
This option tells how many bytes in a row have to be the same between the old and new files for diffbin to consider the files to match at that point.

diffbin works by dividing the files into areas where the files match, areas where one file has stuff that is missing from the other, and areas where the two files have different contents.

The default is 8.

-context=bytecount
This option tells diffbin how many non-differing bytes on either side of a difference to include in the output.

The default is 0.

You can't specify both -context and -all.

-all

This option says to include all of the contents of both files in the output -- the differing and nondiffering parts alike. It's like -context with infinity as the value.

You can't specify both -context and -all.

-ascii
This option says to add to the output the ASCII interpretation of each byte displayed. I.e. the text the characters represent, assuming they are the ASCII encoding of text.

Pedantic terminology note: Some people say the top line is hexadecimal and the bottom line is ASCII. This is wrong. The top line is ASCII (in hexadecimal) and the bottom line is standard typographical text.

-hexpos
This option says to display the file position in hexadecimal; the default is decimal. diffbin displays at the start of each line the file position to which it applies.
Bryan Henderson