Contents | < Browse | Browse >
Binary Files and Forcing Text Comparisons
=========================================
If `diff' thinks that either of the two files it is comparing is
binary (a non-text file), it normally treats that pair of files much as
if the summary output format had been selected (Brief), and
reports only that the binary files are different. This is because line
by line comparisons are usually not meaningful for binary files.
`diff' determines whether a file is text or binary by checking the
first few bytes in the file; the exact number of bytes is system
dependent, but it is typically several thousand. If every character in
that part of the file is non-null, `diff' considers the file to be
text; otherwise it considers the file to be binary.
Sometimes you might want to force `diff' to consider files to be
text. For example, you might be comparing text files that contain null
characters; `diff' would erroneously decide that those are non-text
files. Or you might be comparing documents that are in a format used
by a word processing system that uses null characters to indicate
special formatting. You can force `diff' to consider all files to be
text files, and compare them line by line, by using the `-a' or
`--text' option. If the files you compare using this option do not in
fact contain text, they will probably contain few newline characters,
and the `diff' output will consist of hunks showing differences between
long lines of whatever characters the files contain.
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.
If you want to compare two files byte by byte, you can use the `cmp'
program with the `-l' option to show the values of each differing byte
in the two files. With GNU `cmp', you can also use the `-c' option to
show the ASCII representation of those bytes. Invoking cmp ,
for more information.
If `diff3' thinks that any of the files it is comparing is binary (a
non-text file), it normally reports an error, because such comparisons
are usually not useful. `diff3' uses the same test as `diff' to decide
whether a file is binary. As with `diff', if the input files contain a
few non-text characters but otherwise are like text files, you can
force `diff3' to consider all files to be text files and compare them
line by line by using the `-a' or `--text' options.