Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / gnu / usr.bin / diff / diff.1
1 .\" $FreeBSD: src/gnu/usr.bin/diff/diff.1,v 1.6.2.1 2003/02/23 17:49:08 keramida Exp $
2 .\" $DragonFly: src/gnu/usr.bin/diff/Attic/diff.1,v 1.2 2003/06/17 04:25:45 dillon Exp $
3 .TH DIFF 1 "22sep1993" "GNU Tools" "GNU Tools"
4 .SH NAME
5 diff \- find differences between two files
6 .SH SYNOPSIS
7 .B diff
8 [options] from-file to-file
9 .SH DESCRIPTION
10 In the simplest case, 
11 .I diff
12 compares the contents of the two files
13 .I from-file
14 and
15 .IR to-file .
16 A file name of
17 .B \-
18 stands for
19 text read from the standard input.  As a special case,
20 .B "diff \- \-"
21 compares a copy of standard input to itself.
22
23 If 
24 .I from-file
25 is a directory and
26 .I to-file
27 is not,
28 .I diff
29 compares the file in
30 .I from-file
31 whose file name is that of
32 .IR to-file ,
33 and vice versa.  The non-directory file must not be
34 .BR \- .
35
36 If both
37 .I from-file
38 and
39 .I to-file
40 are directories,
41 .I diff
42 compares corresponding files in both directories, in
43 alphabetical order; this comparison is not recursive unless the
44 .B \-r
45 or
46 .B \-\-recursive
47 option is given.
48 .I diff
49 never
50 compares the actual contents of a directory as if it were a file.  The
51 file that is fully specified may not be standard input, because standard
52 input is nameless and the notion of ``file with the same name'' does not
53 apply.
54
55 .B diff
56 options begin with
57 .BR \- ,
58 so normally
59 .I from-file
60 and
61 .I to-file
62 may not begin with
63 .BR \- .
64 However,
65 .B \-\-
66 as an
67 argument by itself treats the remaining arguments as file names even if
68 they begin with
69 .BR \- .
70 .SS Options
71 Below is a summary of all of the options that GNU
72 .I diff
73 accepts.
74 Most options have two equivalent names, one of which is a single letter
75 preceded by
76 .BR \- ,
77 and the other of which is a long name preceded by
78 .BR \-\- .
79 Multiple single letter options (unless they take an
80 argument) can be combined into a single command line word:
81 .B \-ac
82 is
83 equivalent to
84 .BR "\-a \-c" .
85 Long named options can be abbreviated to
86 any unique prefix of their name.  Brackets
87 .RB ( [
88 and
89 .BR ] )
90 indicate that an
91 option takes an optional argument.
92 .TP
93 .BI \- lines
94 Show
95 .I lines
96 (an integer) lines of context.  This option does not
97 specify an output format by itself; it has no effect unless it is
98 combined with
99 .B \-c
100 or
101 .BR \-u .
102 This option is obsolete.  For proper
103 operation,
104 .I patch
105 typically needs at least two lines of context.
106 .TP
107 .B \-a
108 Treat all files as text and compare them line-by-line, even if they
109 do not seem to be text.
110 .TP
111 .B \-b
112 Ignore changes in amount of white space.
113 .TP
114 .B \-B
115 Ignore changes that just insert or delete blank lines.
116 .TP
117 .B \-\-brief
118 Report only whether the files differ, not the details of the
119 differences.
120 .TP
121 .B \-c
122 Use the context output format.
123 .TP
124 .BI "\-C " lines
125 .br
126 .ns
127 .TP
128 .BI \-\-context[= lines ]
129 Use the context output format, showing
130 .I lines
131 (an integer) lines of
132 context, or three if
133 .I lines
134 is not given.
135 For proper operation,
136 .I patch
137 typically needs at least two lines of
138 context.
139 .TP
140 .BI \-\-changed\-group\-format= format
141 Use
142 .I format
143 to output a line group containing differing lines from
144 both files in if-then-else format.
145 For more details on what can be specified in the
146 .I format
147 string, consult the info documentation of
148 .I diff .
149 .TP
150 .B \-d
151 Change the algorithm to perhaps find a smaller set of changes.  This makes
152 .I diff
153 slower (sometimes much slower).
154 .TP
155 .BI "\-D " name
156 Make merged if-then-else format output, conditional on the preprocessor
157 macro
158 .IR name .
159 .TP
160 .B \-e
161 .br
162 .ns
163 .TP
164 .B \-\-ed
165 Make output that is a valid
166 .I ed
167 script.
168 .TP
169 .BI \-\-exclude= pattern
170 When comparing directories, ignore files and subdirectories whose basenames
171 match
172 .IR pattern .
173 .TP
174 .BI \-\-exclude\-from= file
175 When comparing directories, ignore files and subdirectories whose basenames
176 match any pattern contained in
177 .IR file .
178 .TP
179 .B \-\-expand\-tabs
180 Expand tabs to spaces in the output, to preserve the alignment of tabs
181 in the input files.
182 .TP
183 .B \-f
184 Make output that looks vaguely like an
185 .I ed
186 script but has changes
187 in the order they appear in the file.
188 .TP
189 .BI "\-F " regexp
190 In context and unified format, for each hunk of differences, show some
191 of the last preceding line that matches
192 .IR regexp .
193 .TP
194 .B \-\-forward\-ed
195 Make output that looks vaguely like an
196 .B ed
197 script but has changes
198 in the order they appear in the file.
199 .TP
200 .B \-h
201 This option currently has no effect; it is present for Unix
202 compatibility.
203 .TP
204 .B \-H
205 Use heuristics to speed handling of large files that have numerous
206 scattered small changes.
207 .TP
208 .BI \-\-horizon\-lines= lines
209 Do not discard the last
210 .I lines
211 lines of the common prefix
212 and the first
213 .I lines
214 lines of the common suffix.
215 .TP
216 .B \-i
217 Ignore changes in case; consider upper- and lower-case letters
218 equivalent.
219 .TP
220 .BI "\-I " regexp
221 Ignore changes that just insert or delete lines that match
222 .IR regexp .
223 .TP
224 .BI \-\-ifdef= name
225 Make merged if-then-else format output, conditional on the preprocessor
226 macro
227 .IR name .
228 .TP
229 .B \-\-ignore\-all\-space
230 Ignore white space when comparing lines.
231 .TP
232 .B \-\-ignore\-blank\-lines
233 Ignore changes that just insert or delete blank lines.
234 .TP
235 .B \-\-ignore\-case
236 Ignore changes in case; consider upper- and lower-case to be the same.
237 .TP
238 .BI \-\-ignore\-matching\-lines= regexp
239 Ignore changes that just insert or delete lines that match
240 .IR regexp .
241 .TP
242 .B \-\-ignore\-space\-change
243 Ignore changes in amount of white space.
244 .TP
245 .B \-\-initial\-tab
246 Output a tab rather than a space before the text of a line in normal or
247 context format.  This causes the alignment of tabs in the line to look
248 normal.
249 .TP
250 .B \-l
251 Pass the output through
252 .I pr
253 to paginate it.
254 .TP
255 .BI "\-L " label
256 .br
257 .ns
258 .TP
259 .BI \-\-label= label
260 Use
261 .I label
262 instead of the file name in the context format
263 and unified format
264 headers.
265 .TP
266 .B \-\-left\-column
267 Print only the left column of two common lines in side by side format.
268 .TP
269 .BI \-\-line\-format= format
270 Use
271 .I format
272 to output all input lines in in-then-else format.
273 .TP
274 .B \-\-minimal
275 Change the algorithm to perhaps find a smaller set of changes.  This
276 makes
277 .I diff
278 slower (sometimes much slower).
279 .TP
280 .B \-n
281 Output RCS-format diffs; like
282 .B \-f
283 except that each command
284 specifies the number of lines affected.
285 .TP
286 .B \-N
287 .br
288 .ns
289 .TP
290 .B \-\-new\-file
291 In directory comparison, if a file is found in only one directory,
292 treat it as present but empty in the other directory.
293 .TP
294 .BI \-\-new\-group\-format= format
295 Use
296 .I format
297 to output a group of lines taken from just the second
298 file in if-then-else format.
299 .TP
300 .BI \-\-new\-line\-format= format
301 Use 
302 .I format
303 to output a line taken from just the second file in
304 if-then-else format.
305 .TP
306 .B \-o
307 Use the old traditional output format.
308 .TP
309 .BI \-\-old\-group\-format= format
310 Use
311 .I format
312 to output a group of lines taken from just the first
313 file in if-then-else format.
314 .TP
315 .BI \-\-old\-line\-format= format
316 Use
317 .I format
318 to output a line taken from just the first file in
319 if-then-else format.
320 .TP
321 .B \-p
322 Show which C function each change is in.
323 .TP
324 .B \-P
325 When comparing directories, if a file appears only in the second
326 directory of the two, treat it as present but empty in the other.
327 .TP
328 .B \-\-paginate
329 Pass the output through
330 .I pr
331 to paginate it.
332 .TP
333 .B \-q
334 Report only whether the files differ, not the details of the
335 differences.
336 .TP
337 .B \-\-rcs
338 Output RCS-format diffs; like
339 .B \-f
340 except that each command
341 specifies the number of lines affected.
342 .TP
343 .B \-r
344 .br
345 .ns
346 .TP
347 .B \-\-recursive
348 When comparing directories, recursively compare any subdirectories
349 found.
350 .TP
351 .B \-s
352 .br
353 .ns
354 .TP
355 .B \-\-report\-identical\-files
356 Report when two files are the same.
357 .TP
358 .BI "\-S " file
359 When comparing directories, start with the file
360 .IR file .
361 This is
362 used for resuming an aborted comparison.
363 .TP
364 .B \-\-sdiff\-merge\-assist
365 Print extra information to help
366 .IR sdiff .
367 .I sdiff
368 uses this
369 option when it runs
370 .IR diff .
371 This option is not intended for users
372 to use directly.
373 .TP
374 .B \-\-show\-c\-function
375 Show which C function each change is in.
376 .TP
377 .BI \-\-show\-function\-line= regexp
378 In context and unified format, for each hunk of differences, show some
379 of the last preceding line that matches
380 .IR regexp .
381 .TP
382 .B \-\-side\-by\-side
383 Use the side by side output format.
384 .TP
385 .B \-\-speed\-large\-files
386 Use heuristics to speed handling of large files that have numerous
387 scattered small changes.
388 .TP
389 .BI \-\-starting\-file= file
390 When comparing directories, start with the file
391 .IR file .
392 This is
393 used for resuming an aborted comparison.
394 .TP
395 .B \-\-suppress\-common\-lines
396 Do not print common lines in side by side format.
397 .TP
398 .B \-t
399 Expand tabs to spaces in the output, to preserve the alignment of tabs
400 in the input files.
401 .TP
402 .B \-T
403 Output a tab rather than a space before the text of a line in normal or
404 context format.  This causes the alignment of tabs in the line to look
405 normal.
406 .TP
407 .B \-\-text
408 Treat all files as text and compare them line-by-line, even if they
409 do not appear to be text.
410 .TP
411 .B \-u
412 Use the unified output format.
413 .TP
414 .BI \-\-unchanged\-group\-format= format
415 Use
416 .I format
417 to output a group of common lines taken from both files
418 in if-then-else format.
419 .TP
420 .BI \-\-unchanged\-line\-format= format
421 Use
422 .I format
423 to output a line common to both files in if-then-else
424 format.
425 .TP
426 .B \-\-unidirectional\-new\-file
427 When comparing directories, if a file appears only in the second
428 directory of the two, treat it as present but empty in the other.
429 .TP
430 .BI "\-U " lines
431 .br
432 .ns
433 .TP
434 .BI \-\-unified[= lines ]
435 Use the unified output format, showing
436 .I lines
437 (an integer) lines of
438 context, or three if
439 .I lines
440 is not given.
441 For proper operation,
442 .I patch
443 typically needs at least two lines of
444 context.
445 .TP
446 .B \-v
447 .br
448 .ns
449 .TP
450 .B \-\-version
451 Output the version number of
452 .IR diff .
453 .TP
454 .B \-w
455 Ignore horizontal white space when comparing lines.
456 .TP
457 .BI "\-W " columns
458 .br
459 .ns
460 .TP
461 .BI \-\-width= columns
462 Use an output width of
463 .I columns
464 in side by side format.
465 .TP
466 .BI "\-x " pattern
467 When comparing directories, ignore files and subdirectories whose basenames
468 match
469 .IR pattern .
470 .TP
471 .BI "\-X " file
472 When comparing directories, ignore files and subdirectories whose basenames
473 match any pattern contained in
474 .IR file .
475 .TP
476 .B \-y
477 Use the side by side output format.
478 .SH ENVIRONMENT
479 The environment variable
480 .B DIFF_OPTIONS
481 can hold a set of default
482 options for
483 .I diff.
484 These options are interpreted first and can be overwritten by explicit command
485 line parameters.
486 .SH EXAMPLES
487 To save to a file some changes that you have made to your local source
488 tree (possibly including new files), which you would like to show to others
489 (perhaps using the
490 .B send-pr(1)
491 program), you could type
492 .sp
493 diff -crN foo.orig foo >foo.diff
494 .sp
495 where
496 .I foo.orig
497 and
498 .I foo
499 might be directory hierarchies or single files.
500 .SH SEE ALSO
501 cmp(1), comm(1), diff3(1), ed(1), patch(1), pr(1), sdiff(1).
502 .SH DIAGNOSTICS
503 An exit status of 0 means no differences were found, 1 means some
504 differences were found, and 2 means trouble.