summaryrefslogtreecommitdiff
path: root/usr/src/man/man1/diff.1
blob: b3f54b09cb513e5630211df9170f200c725d7798 (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
.\"
.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
.\" permission to reproduce portions of its copyrighted documentation.
.\" Original documentation from The Open Group can be obtained online at
.\" http://www.opengroup.org/bookstore/.
.\"
.\" The Institute of Electrical and Electronics Engineers and The Open
.\" Group, have given us permission to reprint portions of their
.\" documentation.
.\"
.\" In the following statement, the phrase ``this text'' refers to portions
.\" of the system documentation.
.\"
.\" Portions of this text are reprinted and reproduced in electronic form
.\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
.\" Standard for Information Technology -- Portable Operating System
.\" Interface (POSIX), The Open Group Base Specifications Issue 6,
.\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
.\" Engineers, Inc and The Open Group.  In the event of any discrepancy
.\" between these versions and the original IEEE and The Open Group
.\" Standard, the original IEEE and The Open Group Standard is the referee
.\" document.  The original Standard can be obtained online at
.\" http://www.opengroup.org/unix/online.html.
.\"
.\" This notice shall appear on any product containing this material.
.\"
.\" The contents of this file are subject to the terms of the
.\" Common Development and Distribution License (the "License").
.\" You may not use this file except in compliance with the License.
.\"
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
.\" or http://www.opensolaris.org/os/licensing.
.\" See the License for the specific language governing permissions
.\" and limitations under the License.
.\"
.\" When distributing Covered Code, include this CDDL HEADER in each
.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
.\" If applicable, add the following below this CDDL HEADER, with the
.\" fields enclosed by brackets "[]" replaced with your own identifying
.\" information: Portions Copyright [yyyy] [name of copyright owner]
.\"
.\"
.\" Copyright 1989 AT&T
.\" Portions Copyright (c) 1992, X/Open Company Limited.  All Rights Reserved.
.\" Copyright (c) 2004, Sun Microsystems, Inc.  All Rights Reserved.
.\"
.TH DIFF 1 "Sep 22, 2004"
.SH NAME
diff \- compare two files
.SH SYNOPSIS
.LP
.nf
\fBdiff\fR [\fB-bitw\fR] [\fB-c\fR | \fB-e\fR | \fB-f\fR | \fB-h\fR | \fB-n\fR | \fB-u\fR] \fIfile1\fR \fIfile2\fR
.fi

.LP
.nf
\fBdiff\fR [\fB-bitw\fR] [\fB-C\fR \fInumber\fR | \fB-U\fR \fInumber\fR] \fIfile1\fR \fIfile2\fR
.fi

.LP
.nf
\fBdiff\fR [\fB-bitw\fR] [\fB-D\fR \fIstring\fR] \fIfile1\fR \fIfile2\fR
.fi

.LP
.nf
\fBdiff\fR [\fB-bitw\fR] [\fB-c\fR | \fB-e\fR | \fB-f\fR | \fB-h\fR | \fB-n\fR | \fB-u\fR] [\fB-l\fR] [\fB-r\fR] [\fB-s\fR]
     [\fB-S\fR \fIname\fR] \fIdirectory1\fR \fIdirectory2\fR
.fi

.SH DESCRIPTION
.sp
.LP
The \fBdiff\fR utility will compare the contents of \fIfile1\fR and \fIfile2\fR
and write to standard output a list of changes necessary to convert \fIfile1\fR
into \fIfile2\fR. This list should be minimal. Except in rare circumstances,
\fBdiff\fR finds a smallest sufficient set of file differences. No output will
be produced if the files are identical.
.sp
.LP
The normal output contains lines of these forms:
.sp
.in +2
.nf
\fIn1\fR \fBa\fR \fIn3,n4\fR
\fIn1,n2\fR \fBd\fR \fIn3\fR
\fIn1,n2\fR \fBc\fR \fIn3,n4\fR
.fi
.in -2
.sp

.sp
.LP
where \fIn1\fR and \fIn2\fR represent lines \fIfile1\fR and \fIn3\fR and
\fIn4\fR represent lines in \fIfile2\fR These lines resemble \fBed\fR(1)
commands to convert \fIfile1\fR to \fIfile2\fR. By exchanging \fBa\fR for
\fBd\fR and reading backward, \fIfile2\fR can be converted to \fIfile1\fR. As
in \fBed\fR, identical pairs, where \fIn1\fR=\fIn2\fR or \fIn3\fR=\fIn4\fR, are
abbreviated as a single number.
.sp
.LP
Following each of these lines come all the lines that are affected in the first
file flagged by `\|\fB<\fR\|', then all the lines that are affected in the
second file flagged by `\|\fB>\fR\|'.
.SH OPTIONS
.sp
.LP
The following options are supported:
.sp
.ne 2
.na
\fB\fB-b\fR \fR
.ad
.RS 7n
Ignores trailing blanks (spaces and tabs) and treats other strings of blanks as
equivalent.
.RE

.sp
.ne 2
.na
\fB\fB-i\fR \fR
.ad
.RS 7n
Ignores the case of letters. For example, `\fBA\fR' will compare equal to
`\fBa\fR'.
.RE

.sp
.ne 2
.na
\fB\fB-t\fR \fR
.ad
.RS 7n
Expands TAB characters in output lines. Normal or \fB-c\fR output adds
character(s) to the front of each line that may adversely affect the
indentation of the original source lines and make the output lines difficult to
interpret. This option will preserve the original source's indentation.
.RE

.sp
.ne 2
.na
\fB\fB-w\fR \fR
.ad
.RS 7n
Ignores all blanks (SPACE and TAB characters) and treats all other strings of
blanks as equivalent. For example, `\fBif ( a =\|= b )\fR' will compare equal
to `\fBif(a=\|=b)\fR'.
.RE

.sp
.LP
The following options are mutually exclusive:
.sp
.ne 2
.na
\fB\fB-c\fR \fR
.ad
.RS 14n
Produces a listing of differences with three lines of context. With this
option, output format is modified slightly. That is, output begins with
identification of the files involved and their creation dates, then each change
is separated by a line with a dozen \fB*\fR's. The lines removed from
\fIfile1\fR are marked with '\(em'. The lines added to \fIfile2\fR are
marked '\|+\|'. Lines that are changed from one file to the other are marked in both
files with '\|!\|'.
.RE

.sp
.ne 2
.na
\fB\fB-C\fR \fInumber\fR \fR
.ad
.RS 14n
Produces a listing of differences identical to that produced by \fB-c\fR with
\fInumber\fR lines of context.
.RE

.sp
.ne 2
.na
\fB\fB-D\fR \fIstring\fR \fR
.ad
.RS 14n
Creates a merged version of \fIfile1\fR and \fIfile2\fR with C preprocessor
controls included so that a compilation of the result without defining
\fIstring\fR is equivalent to compiling \fIfile1\fR, while defining
\fIstring\fR will yield \fIfile2\fR.
.RE

.sp
.ne 2
.na
\fB\fB-e\fR \fR
.ad
.RS 14n
Produces a script of only \fBa\fR, \fBc\fR, and \fBd\fR commands for the editor
\fBed\fR, which will recreate \fIfile2\fR from \fIfile1\fR. In connection with
the \fB-e\fR option, the following shell program may help maintain multiple
versions of a file. Only an ancestral file ($1) and a chain of
version-to-version \fBed\fR scripts ($2,$3,...) made by \fBdiff\fR need be on
hand. A ``latest version'' appears on the standard output.
.sp
.in +2
.nf
(shift; cat $*; echo a\'1,$p') | ed \(mi $1
.fi
.in -2
.sp

.RE

.sp
.ne 2
.na
\fB\fB-f\fR \fR
.ad
.RS 13n
Produces a similar script, not useful with \fBed\fR, in the opposite order.
.RE

.sp
.ne 2
.na
\fB\fB-h\fR \fR
.ad
.RS 13n
Does a fast, half-hearted job. It works only when changed stretches are short
and well separated, but does work on files of unlimited length. Options
\fB-c\fR, \fB-C\fR, \fB-D\fR, \fB-e\fR, \fB-f\fR, and \fB-n\fR are unavailable
with \fB-h\fR. \fBdiff\fR does not descend into directories with this option.
.RE

.sp
.ne 2
.na
\fB\fB-n\fR \fR
.ad
.RS 13n
Produces a script similar to \fB-e\fR, but in the opposite order and with a
count of changed lines on each insert or delete command.
.RE

.sp
.ne 2
.na
\fB\fB-u\fR\fR
.ad
.RS 13n
Produces a listing of differences with three lines of context. The output is
similar to that of the \fB-c\fR option, except that the context is "unified".
Removed and changed lines in \fIfile1\fR are marked by a '\fB-\fR' while lines
added or changed in \fIfile2\fR are marked by a '\fB+\fR'. Both versions of
changed lines appear in the output, while added, removed, and context lines
appear only once. The identification of \fIfile1\fR and \fIfile2\fR is
different, with "\fB\(mi\(mi\(mi\fR" and "\fB+++\fR" being printed where
"\fB***\fR" and "\fB\(mi\(mi\(mi\fR" would appear with the \fB-c\fR option.
Each change is separated by a line of the form
.sp
.in +2
.nf
\fB@@ -\fIn1\fR,\fIn2\fR +\fIn3\fR,\fIn4\fR @@\fR
.fi
.in -2
.sp

.RE

.sp
.ne 2
.na
\fB\fB-U\fR \fInumber\fR\fR
.ad
.RS 13n
Produces a listing of differences identical to that produced by \fB-u\fR with
\fInumber\fR lines of context.
.RE

.sp
.LP
The following options are used for comparing directories:
.sp
.ne 2
.na
\fB\fB-l\fR \fR
.ad
.RS 12n
Produces output in long format. Before the \fBdiff\fR, each text file is piped
through \fBpr\fR(1) to paginate it. Other differences are remembered and
summarized after all text file differences are reported.
.RE

.sp
.ne 2
.na
\fB\fB-r\fR \fR
.ad
.RS 12n
Applies \fBdiff\fR recursively to common subdirectories encountered.
.RE

.sp
.ne 2
.na
\fB\fB-s\fR \fR
.ad
.RS 12n
Reports files that are identical. These identical files would not otherwise be
mentioned.
.RE

.sp
.ne 2
.na
\fB\fB-S\fR \fIname\fR \fR
.ad
.RS 12n
Starts a directory \fBdiff\fR in the middle, beginning with the file
\fIname\fR.
.RE

.SH OPERANDS
.sp
.LP
The following operands are supported:
.sp
.ne 2
.na
\fB\fIfile1\fR \fR
.ad
.br
.na
\fB\fIfile2\fR\fR
.ad
.RS 15n
A path name of a file or directory to be compared. If either \fIfile1\fR or
\fIfile2\fR is \fB\(mi\fR, the standard input will be used in its place.
.RE

.sp
.ne 2
.na
\fB\fIdirectory1\fR \fR
.ad
.br
.na
\fB\fIdirectory2\fR\fR
.ad
.RS 15n
A path name of a directory to be compared.
.RE

.sp
.LP
If only one of \fIfile1\fR and \fIfile2\fR is a directory, \fBdiff\fR will be
applied to the non-directory file and the file contained in the directory file
with a filename that is the same as the last component of the non-directory
file.
.SH USAGE
.sp
.LP
See \fBlargefile\fR(5) for the description of the behavior of \fBdiff\fR when
encountering files greater than or equal to 2 Gbyte ( 2^31 bytes).
.SH EXAMPLES
.LP
\fBExample 1 \fRTypical output of the diff command
.sp
.LP
In the following command, \fBdir1\fR is a directory containing a directory
named \fBx\fR, \fBdir2\fR is a directory containing a directory named \fBx\fR,
\fBdir1/x\fR and \fBdir2/x\fR both contain files named \fBdate.out\fR, and
\fBdir2/x\fR contains a file named \fBy\fR:

.sp
.in +2
.nf
example% \fBdiff -r dir1 dir2\fR
Common subdirectories: dir1/x and dir2/x

Only in dir2/x: y

diff -r dir1/x/date.out dir2/x/date.out

1c1

< Mon Jul  2 13:12:16 PDT 1990

---

> Tue Jun 19 21:41:39 PDT 1990
.fi
.in -2
.sp

.SH ENVIRONMENT VARIABLES
.sp
.LP
See \fBenviron\fR(5) for descriptions of the following environment variables
that affect the execution of \fBdiff\fR: \fBLANG\fR, \fBLC_ALL\fR,
\fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, \fBLC_TIME\fR, and \fBNLSPATH\fR.
.sp
.ne 2
.na
\fB\fBTZ\fR \fR
.ad
.RS 7n
Determines the locale for affecting the timezone used for calculating file
timestamps written with the \fB-C\fR and \fB-c\fR options.
.RE

.SH EXIT STATUS
.sp
.LP
The following exit values are returned:
.sp
.ne 2
.na
\fB\fB0\fR \fR
.ad
.RS 7n
No differences were found.
.RE

.sp
.ne 2
.na
\fB\fB1\fR \fR
.ad
.RS 7n
Differences were found.
.RE

.sp
.ne 2
.na
\fB\fB>1\fR \fR
.ad
.RS 7n
An error occurred.
.RE

.SH FILES
.sp
.ne 2
.na
\fB\fB/tmp/d?????\fR \fR
.ad
.RS 19n
temporary file used for comparison
.RE

.sp
.ne 2
.na
\fB\fB/usr/lib/diffh\fR \fR
.ad
.RS 19n
executable file for \fB-h\fR option
.RE

.SH ATTRIBUTES
.sp
.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
CSI	Enabled
_
Interface Stability	Standard
.TE

.SH SEE ALSO
.sp
.LP
\fBbdiff\fR(1), \fBcmp\fR(1), \fBcomm\fR(1), \fBdircmp\fR(1), \fBed\fR(1),
\fBpr\fR(1), \fBsdiff\fR(1), \fBattributes\fR(5), \fBenviron\fR(5),
\fBlargefile\fR(5), \fBstandards\fR(5)
.SH NOTES
.sp
.LP
Editing scripts produced under the \fB-e\fR or \fB-f\fR options are naive about
creating lines consisting of a single period (\fB\&.\fR).
.sp
.LP
Missing NEWLINE at end of file indicates that the last line of the file in
question did not have a NEWLINE. If the lines are different, they will be
flagged and output, although the output will seem to indicate they are the
same.