Commit | Line | Data |
---|---|---|
f87ab605 KM |
1 | .\" Copyright (c) 1980 Regents of the University of California. |
2 | .\" All rights reserved. The Berkeley software License Agreement | |
3 | .\" specifies the terms and conditions for redistribution. | |
4 | .\" | |
2f72f02a | 5 | .\" @(#)diff.1 6.1 (Berkeley) %G% |
f87ab605 | 6 | .\" |
2f72f02a | 7 | .TH DIFF 1 "" |
f87ab605 KM |
8 | .UC 4 |
9 | .SH NAME | |
10 | diff \- differential file and directory comparator | |
11 | .SH SYNOPSIS | |
12 | .B diff | |
13 | [ | |
14 | .B \-l | |
15 | ] [ | |
16 | .B \-r | |
17 | ] [ | |
18 | .B \-s | |
19 | ] [ | |
20 | \fB\-cefh\fR | |
21 | ] [ | |
22 | .B \-b | |
23 | ] dir1 dir2 | |
24 | .br | |
25 | .B diff | |
26 | [ | |
27 | \fB\-cefh | |
28 | ] [ | |
29 | \fB\-b\fR | |
30 | ] file1 file2 | |
31 | .br | |
32 | .B diff | |
33 | [ | |
34 | .BI \-D string | |
35 | ] [ | |
36 | .B \-b | |
37 | ] | |
38 | file1 file2 | |
39 | .SH DESCRIPTION | |
40 | If both arguments are directories, | |
41 | .I diff | |
42 | sorts the contents of the directories by name, and then runs the | |
43 | regular file | |
44 | .I diff | |
45 | algorithm (described below) | |
46 | on text files which are different. | |
47 | Binary files which differ, | |
48 | common subdirectories, and files which appear in only one directory | |
49 | are listed. | |
50 | Options when comparing directories are: | |
51 | .TP | |
52 | .B \-l | |
53 | long output format; each text file | |
54 | .I diff | |
55 | is piped through | |
56 | .IR pr (1) | |
57 | to paginate it, | |
58 | other differences are remembered and summarized | |
59 | after all text file differences are reported. | |
60 | .TP | |
61 | .B \-r | |
62 | causes application of | |
63 | .I diff | |
64 | recursively to common subdirectories encountered. | |
65 | .TP | |
66 | .B \-s | |
67 | causes | |
68 | .I diff | |
69 | to report files which are the same, which are otherwise not mentioned. | |
70 | .TP | |
71 | .B \-Sname | |
72 | starts a directory | |
73 | .I diff | |
74 | in the middle beginning with file | |
75 | .I name. | |
76 | .PP | |
77 | When run on regular files, and when comparing text files which differ | |
78 | during directory comparison, | |
79 | .I diff | |
80 | tells what lines must be changed in the files to bring them into agreement. | |
81 | Except in rare circumstances, | |
82 | .I diff | |
83 | finds a smallest sufficient set of file differences. | |
84 | If neither | |
85 | .I file1 | |
86 | nor | |
87 | .I file2 | |
88 | is a directory, then either | |
89 | may be given as `\-', in which case the standard input is used. | |
90 | If | |
91 | .I file1 | |
92 | is a directory, | |
93 | then a file in that directory whose file-name is the same as the file-name of | |
94 | .I file2 | |
95 | is used (and vice versa). | |
96 | .PP | |
97 | There are several options for output format; | |
98 | the default output format contains lines of these forms: | |
99 | .IP "" 5 | |
100 | .I n1 | |
101 | a | |
102 | .I n3,n4 | |
103 | .br | |
104 | .I n1,n2 | |
105 | d | |
106 | .I n3 | |
107 | .br | |
108 | .I n1,n2 | |
109 | c | |
110 | .I n3,n4 | |
111 | .PP | |
112 | These lines resemble | |
113 | .I ed | |
114 | commands to convert | |
115 | .I file1 | |
116 | into | |
117 | .IR file2 . | |
118 | The numbers after the letters pertain to | |
119 | .IR file2 . | |
120 | In fact, by exchanging `a' for `d' and reading backward | |
121 | one may ascertain equally how to convert | |
122 | .I file2 | |
123 | into | |
124 | .IR file1 . | |
125 | As in | |
126 | .I ed, | |
127 | identical pairs where | |
128 | .I n1 | |
129 | = | |
130 | .I n2 | |
131 | or | |
132 | .I n3 | |
133 | = | |
134 | .I n4 | |
135 | are abbreviated as a single number. | |
136 | .PP | |
137 | Following each of these lines come all the lines that are | |
138 | affected in the first file flagged by `<', | |
139 | then all the lines that are affected in the second file | |
140 | flagged by `>'. | |
141 | .PP | |
142 | Except for | |
143 | .B \-b, | |
144 | which may be given with any of the others, | |
145 | the following options are mutually exclusive: | |
146 | .TP 9 | |
147 | .B \-e | |
148 | producing a script of | |
149 | .I "a, c" | |
150 | and | |
151 | .I d | |
152 | commands for the editor | |
153 | .I ed, | |
154 | which will recreate | |
155 | .I file2 | |
156 | from | |
157 | .IR file1 . | |
158 | In connection with | |
159 | .BR \-e , | |
160 | the following shell program may help maintain | |
161 | multiple versions of a file. | |
162 | Only an ancestral file ($1) and a chain of | |
163 | version-to-version | |
164 | .I ed | |
165 | scripts ($2,$3,...) made by | |
166 | .I diff | |
167 | need be on hand. | |
168 | A `latest version' appears on | |
169 | the standard output. | |
170 | .IP | |
171 | \ \ \ \ \ \ \ \ (shift; cat $*; echo \'1,$p\') \(bv ed \- $1 | |
172 | .IP | |
173 | Extra commands are added to the output when comparing directories with | |
174 | .B \-e, | |
175 | so that the result is a | |
176 | .IR sh (1) | |
177 | script for converting text files which are common to the two directories | |
178 | from their state in | |
179 | .I dir1 | |
180 | to their state in | |
181 | .I dir2. | |
182 | .TP 9 | |
183 | .B \-f | |
184 | produces a script similar to that of | |
185 | .B \-e, | |
186 | not useful with | |
187 | .I ed, | |
188 | and in the opposite order. | |
189 | .TP 9 | |
190 | .B \-c | |
191 | produces a diff with lines of context. | |
192 | The default is to present 3 lines of context and may be changed, e.g to 10, by | |
193 | .BR \-c10 \&. | |
194 | With | |
195 | .B \-c | |
196 | the output format is modified slightly: | |
197 | the output beginning with identification of the files involved and | |
198 | their creation dates and then each change is separated | |
199 | by a line with a dozen *'s. | |
200 | The lines removed from | |
201 | .I file1 | |
202 | are marked with `\(mi'; those added to | |
203 | .I file2 | |
204 | are marked `+'. Lines which are changed from one | |
205 | file to the other are marked in both files with `!'. | |
206 | .TP 9 | |
207 | .B \-h | |
208 | does a fast, half-hearted job. | |
209 | It works only when changed stretches are short | |
210 | and well separated, | |
211 | but does work on files of unlimited length. | |
212 | .TP | |
213 | .B \-Dstring | |
214 | causes | |
215 | .I diff | |
216 | to create a merged version of | |
217 | .I file1 | |
218 | and | |
219 | .I file2 | |
220 | on the standard output, with C preprocessor controls included so that | |
221 | a compilation of the result without defining \fIstring\fR is equivalent | |
222 | to compiling | |
223 | .I file1, | |
224 | while defining | |
225 | .I string | |
226 | will yield | |
227 | .I file2. | |
228 | .TP | |
229 | .B \-b | |
230 | causes trailing blanks (spaces and tabs) to be ignored, and other | |
231 | strings of blanks to compare equal. | |
232 | .SH FILES | |
233 | /tmp/d????? | |
234 | .br | |
235 | /usr/lib/diffh for | |
236 | .B \-h | |
237 | .br | |
a4736a6b | 238 | /bin/pr |
f87ab605 KM |
239 | .SH "SEE ALSO" |
240 | cmp(1), cc(1), comm(1), ed(1), diff3(1) | |
241 | .SH DIAGNOSTICS | |
242 | Exit status is 0 for no differences, 1 for some, 2 for trouble. | |
243 | .SH BUGS | |
244 | Editing scripts produced under the | |
245 | .BR \-e " or" | |
246 | .BR \-f " option are naive about" | |
247 | creating lines consisting of a single `\fB.\fR'. | |
248 | .PP | |
249 | When comparing directories with the | |
250 | .B \-b | |
251 | option specified, | |
252 | .I diff | |
253 | first compares the files ala | |
254 | .I cmp, | |
255 | and then decides to run the | |
256 | .I diff | |
257 | algorithm if they are not equal. | |
258 | This may cause a small amount of spurious output if the files | |
259 | then turn out to be identical because the only differences are | |
260 | insignificant blank string differences. |