DIFF(1)
NAME
diff − differential file and directory comparator
USAGE
diff [ −l ] [ −r ] [ −s ] [ −Sname ] [ −cefh ] [ −b ] dir1 dir2
diff [ −cefh ] [ −b ] file1 file2
diff [ −Dstring ] [ −b ] file1 file2
DESCRIPTION
If both arguments are directories, diff sorts the contents of the directories by name, and then compares text files. It lists binary files that differ, common subdirectories, and files that appear in only one directory.
When run on regular files, and when comparing text files that differ during directory comparison, diff tells what lines must be changed in the files to bring them into agreement. Except in rare circumstances, diff finds the smallest sufficient set of file differences. If neither file1 nor file2 is a directory, then either of these two files may be specified as a dash (−) to cause diff to read the standard input. If file1 is a directory, then a file in that directory whose filename is the same as the filename of file2 is used (and vice versa).
You have several options for output format. The default output format contains lines of these forms:
n1 a n3,n4
n1,n2 d n3
n1,n2 c n3,n4
These lines resemble ed(1) commands to convert file1 into file2. The numbers after the letters pertain to file2. In fact, by exchanging a for d and reading backward, you can easily determine how to convert file2 into file1. As in ed(1), identical pairs, where n1 = n2 or n3 = n4, are abbreviated as a single number.
After these lines are printed, each of the lines affected in the first file are flagged by a less-than character (<). Then, all the lines affected in the second file are flagged by a greater-than character (>).
The valid options for diff are presented below. The first three options pertain only to comparisons between directories. The remainder apply to file comparisons. Of those to be used for comparing files, only the −b option is not mutually exclusive and may be specified with any of the others.
OPTIONS
−l Format in long output style. Pipe each text file comparison through pr(1) to paginate it. Remember and summarize other differences after all text file differences are reported.
−r Run a recursive comparison on common subdirectories.
−s Report files that are the same (these are not usually mentioned).
−Sname Begin a directory comparison at the point of the file name.
−e Produce a script of a, c, and d commands for ed(1) to re-create file2 from file1. 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(1) scripts ($2,$3,...) made by diff have to be available. A latest version appears on the standard output:
(shift; cat $*; echo ´1,$p´) │ ed − $1
Extra commands are added to the output when comparing directories with −e, so that the result is a sh(1) script to convert text files common to the two directories from their state in dir1 to their state in dir2.
−f Produce a script similar to that of −e, not useful with ed(1), and in the opposite order.
−c Produce a comparison with lines of context. The default is to present three lines of context that may be changed, for example, to 10, by specifying the following: −c10. With −c the output format is modified slightly: the output beginning with identification of the files involved and their creation dates and then each change is separated by a line with a dozen asterisks. The lines removed from file1 are marked with dashes; those added to file2 are marked with plus signs. Lines changed from one file to the other are marked in both files with exclamation points.
−h Do a quick (but often incomplete) comparison. This option is only useful when changed portions of the files are brief and well separated, but it does work on files of unlimited length.
−Dstring Create a merged version of file1 and file2 on the standard output, with C preprocessor controls included so that a compilation of the result without defining string is equivalent to compiling file1, while defining string yields file2.
−b Ignore trailing blanks (spaces and tabs) and cause strings of blanks to compare equal.
CAUTIONS
Editing scripts produced under the −e or −f option are naive about creating lines consisting of a single period.
When using the −b option in comparing directories, diff first compares the files in the manner of cmp(1), and then decides to run the diff algorithm if they are not equal. This may cause a small amount of spurious output if the files are identical except for insignificant blank string differences.
FILES
/tmp/d?????
/usr/lib/diffh for −h
/bin/pr
DIAGNOSTICS
Exit status is 0 for no differences, 1 for some, and 2 for trouble.