1DIFF(1) General Commands Manual DIFF(1)
2
3
4
6 diff - differential file and directory comparator
7
9 diff [ -l ] [ -r ] [ -s ] [ -cefhn ] [ -biwt ] dir1 dir2
10 diff [ -cefhn ] [ -biwt ] file1 file2
11 diff [ -Dstring ] [ -biw ] file1 file2
12
14 If both arguments are directories, diff sorts the contents of the
15 directories by name, and then runs the regular file diff algorithm
16 (described below) on text files which are different. Binary files
17 which differ, common subdirectories, and files which appear in only one
18 directory are listed. Options when comparing directories are:
19
20 -l long output format; each text file diff is piped through pr(1)
21 to paginate it, other differences are remembered and summarized
22 after all text file differences are reported.
23
24 -r causes application of diff recursively to common subdirectories
25 encountered.
26
27 -s causes diff to report files which are the same, which are other‐
28 wise not mentioned.
29
30 -Sname starts a directory diff in the middle beginning with file name.
31
32 When run on regular files, and when comparing text files which differ
33 during directory comparison, diff tells what lines must be changed in
34 the files to bring them into agreement. Except in rare circumstances,
35 diff finds a smallest sufficient set of file differences. If neither
36 file1 nor file2 is a directory, then either may be given as `-', in
37 which case the standard input is used. If file1 is a directory, then a
38 file in that directory whose file-name is the same as the file-name of
39 file2 is used (and vice versa).
40
41 There are several options for output format; the default output format
42 contains lines of these forms:
43
44 n1 a n3,n4
45 n1,n2 d n3
46 n1,n2 c n3,n4
47
48 These lines resemble ed commands to convert file1 into file2. The num‐
49 bers after the letters pertain to file2. In fact, by exchanging `a'
50 for `d' and reading backward one may ascertain equally how to convert
51 file2 into file1. As in ed, identical pairs where n1 = n2 or n3 = n4
52 are abbreviated as a single number.
53
54 Following each of these lines come all the lines that are affected in
55 the first file flagged by `<', then all the lines that are affected in
56 the second file flagged by `>'.
57
58 Except for -b, -w, -i or -t which may be given with any of the others,
59 the following options are mutually exclusive:
60
61 -e produces a script of a, c and d commands for the editor ed,
62 which will recreate file2 from file1. In connection with -e,
63 the following shell program may help maintain multiple ver‐
64 sions of a file. Only an ancestral file ($1) and a chain of
65 version-to-version ed scripts ($2,$3,...) made by diff need be
66 on hand. A `latest version' appears on the standard output.
67
68 (shift; cat $*; echo ´1,$p´) ⎪ ed - $1
69
70 Extra commands are added to the output when comparing directo‐
71 ries with -e, so that the result is a sh(1) script for con‐
72 verting text files which are common to the two directories
73 from their state in dir1 to their state in dir2.
74
75 -f produces a script similar to that of -e, not useful with ed,
76 and in the opposite order.
77
78 -n produces a script similar to that of -e, but in the opposite
79 order and with a count of changed lines on each insert or
80 delete command. This is the form used by rcsdiff(1).
81
82 -c produces a diff with lines of context. The default is to
83 present 3 lines of context and may be changed, e.g to 10, by
84 -c10. With -c the output format is modified slightly: the
85 output beginning with identification of the files involved and
86 their creation dates and then each change is separated by a
87 line with a dozen *'s. The lines removed from file1 are
88 marked with `− '; those added to file2 are marked `+ '. Lines
89 which are changed from one file to the other are marked in
90 both files with with `! '.
91
92 Changes which lie within <context> lines of each other are
93 grouped together on output. (This is a change from the previ‐
94 ous ``diff -c'' but the resulting output is usually much eas‐
95 ier to interpret.)
96
97 -h does a fast, half-hearted job. It works only when changed
98 stretches are short and well separated, but does work on files
99 of unlimited length.
100
101 -Dstring causes diff to create a merged version of file1 and file2 on
102 the standard output, with C preprocessor controls included so
103 that a compilation of the result without defining string is
104 equivalent to compiling file1, while defining string will
105 yield file2.
106
107 -b causes trailing blanks (spaces and tabs) to be ignored, and
108 other strings of blanks to compare equal.
109
110 -w is similar to -b but causes whitespace (blanks and tabs) to be
111 totally ignored. E.g., ``if ( a == b )'' will compare equal
112 to ``if(a==b)''.
113
114 -i ignores the case of letters. E.g., ``A'' will compare equal
115 to ``a''.
116
117 -t will expand tabs in output lines. Normal or -c output adds
118 character(s) to the front of each line which may screw up the
119 indentation of the original source lines and make the output
120 listing difficult to interpret. This option will preserve the
121 original source's indentation.
122
124 /tmp/d?????
125 /usr/libexec/diffh for -h
126 /bin/diff for directory diffs
127 /bin/pr
128
130 cmp(1), cc(1), comm(1), ed(1), diff3(1)
131
133 Exit status is 0 for no differences, 1 for some, 2 for trouble.
134
136 Editing scripts produced under the -e or -f option are naive about cre‐
137 ating lines consisting of a single `.'.
138
139 When comparing directories with the -b, -w or -i options specified,
140 diff first compares the files ala cmp, and then decides to run the diff
141 algorithm if they are not equal. This may cause a small amount of spu‐
142 rious output if the files then turn out to be identical because the
143 only differences are insignificant blank string or case differences.
144
145
146
1474th Berkeley Distribution October 21, 1996 DIFF(1)