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