summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/diff/diff.1
blob: f04d90f934986559da84c2c8aead37d31ebc2d5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
.\" $FreeBSD$
.TH DIFF 1 "22sep1993" "GNU Tools" "GNU Tools"
.SH NAME
diff \- find differences between two files
.SH SYNOPSIS
.B diff
[options] from-file to-file
.SH DESCRIPTION
In the simplest case, 
.I diff
compares the contents of the two files
.I from-file
and
.IR to-file .
A file name of
.B \-
stands for
text read from the standard input.  As a special case,
.B "diff \- \-"
compares a copy of standard input to itself.

If 
.I from-file
is a directory and
.I to-file
is not,
.I diff
compares the file in
.I from-file
whose file name is that of
.IR to-file ,
and vice versa.  The non-directory file must not be
.BR \- .

If both
.I from-file
and
.I to-file
are directories,
.I diff
compares corresponding files in both directories, in
alphabetical order; this comparison is not recursive unless the
.B \-r
or
.B \-\-recursive
option is given.
.I diff
never
compares the actual contents of a directory as if it were a file.  The
file that is fully specified may not be standard input, because standard
input is nameless and the notion of ``file with the same name'' does not
apply.

.B diff
options begin with
.BR \- ,
so normally
.I from-file
and
.I to-file
may not begin with
.BR \- .
However,
.B \-\-
as an
argument by itself treats the remaining arguments as file names even if
they begin with
.BR \- .
.SS Options
Below is a summary of all of the options that GNU
.I diff
accepts.
Most options have two equivalent names, one of which is a single letter
preceded by
.BR \- ,
and the other of which is a long name preceded by
.BR \-\- .
Multiple single letter options (unless they take an
argument) can be combined into a single command line word:
.B \-ac
is
equivalent to
.BR "\-a \-c" .
Long named options can be abbreviated to
any unique prefix of their name.  Brackets
.RB ( [
and
.BR ] )
indicate that an
option takes an optional argument.
.TP
.BI \- lines
Show
.I lines
(an integer) lines of context.  This option does not
specify an output format by itself; it has no effect unless it is
combined with
.B \-c
or
.BR \-u .
This option is obsolete.  For proper
operation,
.I patch
typically needs at least two lines of context.
.TP
.B \-a
Treat all files as text and compare them line-by-line, even if they
do not seem to be text.
.TP
.B \-b
Ignore changes in amount of white space.
.TP
.B \-B
Ignore changes that just insert or delete blank lines.
.TP
.B \-\-brief
Report only whether the files differ, not the details of the
differences.
.TP
.B \-c
Use the context output format.
.TP
.BI "\-C " lines
.br
.ns
.TP
.BI \-\-context[= lines ]
Use the context output format, showing
.I lines
(an integer) lines of
context, or three if
.I lines
is not given.
For proper operation,
.I patch
typically needs at least two lines of
context.
.TP
.BI \-\-changed\-group\-format= format
Use
.I format
to output a line group containing differing lines from
both files in if-then-else format.
For more details on what can be specified in the
.I format
string, consult the info documentation of
.I diff .
.TP
.B \-d
Change the algorithm to perhaps find a smaller set of changes.  This makes
.I diff
slower (sometimes much slower).
.TP
.BI "\-D " name
Make merged if-then-else format output, conditional on the preprocessor
macro
.IR name .
.TP
.B \-e
.br
.ns
.TP
.B \-\-ed
Make output that is a valid
.I ed
script.
.TP
.BI \-\-exclude= pattern
When comparing directories, ignore files and subdirectories whose basenames
match
.IR pattern .
.TP
.BI \-\-exclude\-from= file
When comparing directories, ignore files and subdirectories whose basenames
match any pattern contained in
.IR file .
.TP
.B \-\-expand\-tabs
Expand tabs to spaces in the output, to preserve the alignment of tabs
in the input files.
.TP
.B \-f
Make output that looks vaguely like an
.I ed
script but has changes
in the order they appear in the file.
.TP
.BI "\-F " regexp
In context and unified format, for each hunk of differences, show some
of the last preceding line that matches
.IR regexp .
.TP
.B \-\-forward\-ed
Make output that looks vaguely like an
.B ed
script but has changes
in the order they appear in the file.
.TP
.B \-h
This option currently has no effect; it is present for Unix
compatibility.
.TP
.B \-H
Use heuristics to speed handling of large files that have numerous
scattered small changes.
.TP
.BI \-\-horizon\-lines= lines
Do not discard the last
.I lines
lines of the common prefix
and the first
.I lines
lines of the common suffix.
.TP
.B \-i
Ignore changes in case; consider upper- and lower-case letters
equivalent.
.TP
.BI "\-I " regexp
Ignore changes that just insert or delete lines that match
.IR regexp .
.TP
.BI \-\-ifdef= name
Make merged if-then-else format output, conditional on the preprocessor
macro
.IR name .
.TP
.B \-\-ignore\-all\-space
Ignore white space when comparing lines.
.TP
.B \-\-ignore\-blank\-lines
Ignore changes that just insert or delete blank lines.
.TP
.B \-\-ignore\-case
Ignore changes in case; consider upper- and lower-case to be the same.
.TP
.BI \-\-ignore\-matching\-lines= regexp
Ignore changes that just insert or delete lines that match
.IR regexp .
.TP
.B \-\-ignore\-space\-change
Ignore changes in amount of white space.
.TP
.B \-\-initial\-tab
Output a tab rather than a space before the text of a line in normal or
context format.  This causes the alignment of tabs in the line to look
normal.
.TP
.B \-l
Pass the output through
.I pr
to paginate it.
.TP
.BI "\-L " label
.br
.ns
.TP
.BI \-\-label= label
Use
.I label
instead of the file name in the context format
and unified format
headers.
.TP
.B \-\-left\-column
Print only the left column of two common lines in side by side format.
.TP
.BI \-\-line\-format= format
Use
.I format
to output all input lines in in-then-else format.
.TP
.B \-\-minimal
Change the algorithm to perhaps find a smaller set of changes.  This
makes
.I diff
slower (sometimes much slower).
.TP
.B \-n
Output RCS-format diffs; like
.B \-f
except that each command
specifies the number of lines affected.
.TP
.B \-N
.br
.ns
.TP
.B \-\-new\-file
In directory comparison, if a file is found in only one directory,
treat it as present but empty in the other directory.
.TP
.BI \-\-new\-group\-format= format
Use
.I format
to output a group of lines taken from just the second
file in if-then-else format.
.TP
.BI \-\-new\-line\-format= format
Use 
.I format
to output a line taken from just the second file in
if-then-else format.
.TP
.B \-o
Use the old traditional output format.
.TP
.BI \-\-old\-group\-format= format
Use
.I format
to output a group of lines taken from just the first
file in if-then-else format.
.TP
.BI \-\-old\-line\-format= format
Use
.I format
to output a line taken from just the first file in
if-then-else format.
.TP
.B \-p
Show which C function each change is in.
.TP
.B \-P
When comparing directories, if a file appears only in the second
directory of the two, treat it as present but empty in the other.
.TP
.B \-\-paginate
Pass the output through
.I pr
to paginate it.
.TP
.B \-q
Report only whether the files differ, not the details of the
differences.
.TP
.B \-\-rcs
Output RCS-format diffs; like
.B \-f
except that each command
specifies the number of lines affected.
.TP
.B \-r
.br
.ns
.TP
.B \-\-recursive
When comparing directories, recursively compare any subdirectories
found.
.TP
.B \-s
.br
.ns
.TP
.B \-\-report\-identical\-files
Report when two files are the same.
.TP
.BI "\-S " file
When comparing directories, start with the file
.IR file .
This is
used for resuming an aborted comparison.
.TP
.B \-\-sdiff\-merge\-assist
Print extra information to help
.IR sdiff .
.I sdiff
uses this
option when it runs
.IR diff .
This option is not intended for users
to use directly.
.TP
.B \-\-show\-c\-function
Show which C function each change is in.
.TP
.BI \-\-show\-function\-line= regexp
In context and unified format, for each hunk of differences, show some
of the last preceding line that matches
.IR regexp .
.TP
.B \-\-side\-by\-side
Use the side by side output format.
.TP
.B \-\-speed\-large\-files
Use heuristics to speed handling of large files that have numerous
scattered small changes.
.TP
.BI \-\-starting\-file= file
When comparing directories, start with the file
.IR file .
This is
used for resuming an aborted comparison.
.TP
.B \-\-suppress\-common\-lines
Do not print common lines in side by side format.
.TP
.B \-t
Expand tabs to spaces in the output, to preserve the alignment of tabs
in the input files.
.TP
.B \-T
Output a tab rather than a space before the text of a line in normal or
context format.  This causes the alignment of tabs in the line to look
normal.
.TP
.B \-\-text
Treat all files as text and compare them line-by-line, even if they
do not appear to be text.
.TP
.B \-u
Use the unified output format.
.TP
.BI \-\-unchanged\-group\-format= format
Use
.I format
to output a group of common lines taken from both files
in if-then-else format.
.TP
.BI \-\-unchanged\-line\-format= format
Use
.I format
to output a line common to both files in if-then-else
format.
.TP
.B \-\-unidirectional\-new\-file
When comparing directories, if a file appears only in the second
directory of the two, treat it as present but empty in the other.
.TP
.BI "\-U " lines
.br
.ns
.TP
.BI \-\-unified[= lines ]
Use the unified output format, showing
.I lines
(an integer) lines of
context, or three if
.I lines
is not given.
For proper operation,
.I patch
typically needs at least two lines of
context.
.TP
.B \-v
.br
.ns
.TP
.B \-\-version
Output the version number of
.IR diff .
.TP
.B \-w
Ignore horizontal white space when comparing lines.
.TP
.BI "\-W " columns
.br
.ns
.TP
.BI \-\-width= columns
Use an output width of
.I columns
in side by side format.
.TP
.BI "\-x " pattern
When comparing directories, ignore files and subdirectories whose basenames
match
.IR pattern .
.TP
.BI "\-X " file
When comparing directories, ignore files and subdirectories whose basenames
match any pattern contained in
.IR file .
.TP
.B \-y
Use the side by side output format.
.SH RETURN VALUE
.I diff
returns 0 if the files are identical or 1 if the files differ.
If one or both of the files cannot be opened,
then the return value is set to 2.
.SH ENVIRONMENT
The environment variable
.B DIFF_OPTIONS
can hold a set of default
options for
.I diff.
These options are interpreted first and can be overwritten by explicit command
line parameters.
.SH EXAMPLES
To save to a file some changes that you have made to your local source
tree (possibly including new files), which you would like to show to others
(perhaps using the
.B send-pr(1)
program), you could type
.sp
diff -crN foo.orig foo >foo.diff
.sp
where
.I foo.orig
and
.I foo
might be directory hierarchies or single files.
.SH SEE ALSO
cmp(1), comm(1), diff3(1), ed(1), patch(1), pr(1), sdiff(1).
.SH DIAGNOSTICS
An exit status of 0 means no differences were found, 1 means some
differences were found, and 2 means trouble.
OpenPOWER on IntegriCloud