diff is a differential file comparator. When run on regular files, and when comparing text files that differ during directory comparison (see the notes below on comparing directories), diff tells what lines must be changed in the files to bring them into agreement. Except in rare circumstances, diff finds a smallest sufficient set of differences. If neither filename1 nor filename2 is a directory, either may be given as `-', in which case the standard input is used. If filename1 is a directory, a file in that directory whose filename is the same as the filename of filename2 is used (and vice versa).
There are several options for output format; the default output format contains lines of these forms:
These lines resemble ed.1 commands to convert filename1 into filename2. The numbers after the letters pertain to filename2. In fact, by exchanging a for d and reading backward one may ascertain equally how to convert filename2 into filename1. As in ed.1 identical pairs, where n1 = n2 or n3 = n4, are abbreviated as a single number.
Following each of these lines come all the lines that are affected in the first file flagged by `<', then all the lines that are affected in the second file flagged by `>'.
If both arguments are directories, diff sorts the contents of the directories by name, and then runs the regular file diff program as described above on text files which are different. Binary files which differ, common subdirectories, and files which appear in only one directory are listed.
The following four options are mutually exclusive:
Changes which lie within <context> lines of each other are grouped together on output. This is a change from the previous `diff -c' but the resulting output is usually much easier to interpret.
In connection with
-e,
the following shell program may help
maintain multiple versions of a file.
Only an ancestral file ($1) and a chain of version-to-version
ed
scripts ($2,$3,...) made by
diff
need be on hand.
A `latest version' appears on the standard output.
Extra commands are added to the output when comparing directories with -e, so that the result is a sh script for converting text files which are common to the two directories from their state in directory1 to their state in directory2.
Options for the second form of diff are as follows:
Options when comparing directories are:
The environment variables LC_CTYPE, LANG, and LC_default control the character classification throughout diff. On entry to diff, these environment variables are checked in the following order: LC_CTYPE, LANG, and LC_default. When a valid value is found, remaining environment variables for character classification are ignored. For example, a new setting for LANG does not override the current valid character classification rules of LC_CTYPE. When none of the values is valid, the shell character classification defaults to the POSIX.1 ``C'' locale.
Exit status is 0 for no differences, 1 for some differences, 2 for trouble.
Editing scripts produced under the -e or -f option are naive about creating lines consisting of a single `.'.
When comparing directories with the -b, -w, or -i options specified, diff first compares the files (as in cmp.1 and then runs the regular diff algorithm if they are not equal. This may cause a small amount of spurious output if the files then turn out to be identical because the only differences are insignificant blank string or case differences.
The -D option ignores existing preprocessor controls in the source files, and can generate #ifdefs's with overlapping scope. The output should be checked by hand, or run through `cc -E' (see cc.1v and then diffed with the original source files. Discrepancies revealed should be corrected before compilation.
Created by unroff & hp-tools. © somebody (See intro for details). All Rights Reserved. Last modified 11/5/97