summaryrefslogtreecommitdiff
path: root/usr/src/man/man1/diff.1
blob: 3069149285f325a2c4821fc2a8b598d00b08d833 (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
.\"
.\" 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.
.\" Copyright 2022 OmniOS Community Edition (OmniOSce) Association.
.\"
.Dd February 23, 2022
.Dt DIFF 1
.Os
.Sh NAME
.Nm diff
.Nd compare two files
.Sh SYNOPSIS
.Nm
.Op Fl biqtw
.Op Fl c | e | f | h | n | u
.Ar file1
.Ar file2
.Nm
.Op Fl biqtw
.Op Fl C Ar number | Fl U Ar number
.Ar file1
.Ar file2
.Nm
.Op Fl biqtw
.Op Fl D Ar string
.Ar file1
.Ar file2
.Nm
.Op Fl biqtw
.Op Fl c | e | f | h | n | u
.Op Fl l
.Op Fl r
.Op Fl s
.Op Fl S Ar name
.Ar directory1
.Ar directory2
.Sh DESCRIPTION
The
.Nm
utility will compare the contents of
.Ar file1
and
.Ar file2
and write to standard output a list of changes necessary to convert
.Ar file1
into
.Ar file2 .
This list should be minimal.
Except in rare circumstances,
.Nm
finds a smallest sufficient set of file differences.
No output will be produced if the files are identical.
.Pp
The normal output contains lines of these forms:
.Pp
.Bl -item -offset indent -compact
.Sm off
.It
.Ar n1 Sy a Ar n3 , n4
.It
.Ar n1 , n2 Sy d Ar n3
.It
.Ar n1 , n2 Sy c Ar n3 , n4
.Sm on
.El
.Pp
where
.Ar n1
and
.Ar n2
represent lines in
.Ar file1
and
.Ar n3
and
.Ar n4
represent lines in
.Ar file2
These lines resemble
.Xr ed 1
commands to convert
.Ar file1
to
.Ar file2 .
By exchanging
.Sy a
for
.Sy d
and reading backwards,
.Ar file2
can be converted to
.Ar file1 .
As in
.Xr ed 1 ,
identical pairs, where
.Ar n1 Ns = Ns Ar n2
or
.Ar n3 Ns = Ns Ar n4
are abbreviated as a single number.
.Pp
Following each of these lines come all the lines that are affected in the first
file flagged by
.Sq < ,
then all the lines that are affected in the second file flagged by
.Sq > .
.Sh OPTIONS
The following options are supported:
.Bl -tag -width Ds
.It Fl b
Ignores trailing blanks
.Pq spaces and tabs
and treats other strings of blanks as equivalent.
.It Fl i
Ignores the case of letters.
For example, `
.Sq A
will compare equal to
.Sq a .
.It Fl q
report only when files differ
.It Fl t
Expands TAB characters in output lines.
Normal or
.Fl c
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.
.It Fl w
Ignores all blanks
.Pq SPACE and TAB characters
and treats all other strings of blanks as equivalent.
For example,
.Ql if ( a == b )
will compare equal to
.Ql if (a==b) .
.El
.Pp
The following options are mutually exclusive:
.Bl -tag -width Ds
.It Fl c
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
asterisks
.Pq \&* .
The lines removed from
.Ar file1
are marked with
.Sq -- .
The lines added to
.Ar file2
are marked
.Sq \&+ .
Lines that are changed from one file to the other are marked in both files with
.Sq \&! .
.It Fl C Ar number
Produces a listing of differences identical to that produced by
.Fl c
with
.Ar number
lines of context.
.It Fl D Ar string
Creates a merged version of
.Ar file1
and
.Ar file2
with C preprocessor controls included so that a compilation of the result
without defining
.Ar string
is equivalent to compiling
.Ar file1 ,
while defining
.Ar string
will yield
.Ar file2 .
.It Fl e
Produces a script of only
.Sy a ,
.Sy c ,
and
.Sy d
commands for the editor
.Xr ed 1 ,
which will recreate
.Ar file2
from
.Ar file1 .
In connection with the
.Fl e
option, the following shell program may help maintain multiple versions of a
file.
Only an ancestral file
.Pq $1
and a chain of version-to-version
.Sy ed
scripts
.Pq $2,$3,...
made by
.Nm
need be on hand.
A
.Dq latest version
appears on the standard output.
.Pp
.Dl (shift; cat $*; echo a'1,$p') | ed - $1
.It Fl f
Produces a similar script, not useful with
.Xr ed 1 ,
in the opposite order.
.It Fl h
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
.Fl c ,
.Fl C ,
.Fl D ,
.Fl e ,
.Fl f ,
and
.Fl n
are unavailable with
.Fl h .
.Nm
does not descend into directories with this option.
.It Fl n
Produces a script similar to
.Fl e ,
but in the opposite order and with a count of changed lines on each insert or
delete command.
.It Fl u
Produces a listing of differences with three lines of context.
The output is similar to that of the
.Fl c
option, except that the context is
.Dq unified .
Removed and changed lines in
.Ar file1
are marked by a
.Sq \&-
while lines added or changed in
.Ar file2
are marked by a
.Sq \&+ .
Both versions of changed lines appear in the output, while added, removed, and
context lines appear only once.
The identification of
.Ar file1
and
.Ar file2
is different, with
.Dq ---
and
.Dq +++
being printed where
.Dq ***
and
.Dq ---
would appear with the
.Fl c
option.
Each change is separated by a line of the form
.Pp
.D1 Cm @@ Cm \&- Ns Ar n1 , Ns Ar n2 Cm + Ns Ar n3 , Ns Ar n4 Cm @@
.It Fl U Ar number
Produces a listing of differences identical to that produced by
.Fl u
with
.Ar number
lines of context.
.El
.Pp
The following options are used for comparing directories:
.Bl -tag -width Ds
.It Fl l
Produces output in long format.
Before the
.Nm ,
each text file is piped through
.Xr pr 1
to paginate it.
Other differences are remembered and summarized after all text file differences
are reported.
.It Fl r
Applies
.Nm
recursively to common subdirectories encountered.
.It Fl s
Reports files that are identical.
These identical files would not otherwise be mentioned.
.It Fl S Ar name
Starts a directory
.Nm
in the middle, beginning with the file
.Ar name .
.El
.Sh OPERANDS
The following operands are supported:
.Pp
.Bl -tag -offset Ds -width directory1 -compact
.It Ar file1
.It Ar file2
A path name of a file or directory to be compared.
If either
.Ar file1
or
.Ar file2
is
.Sq \&- ,
the standard input will be used in its place.
.Pp
.It Ar directory1
.It Ar directory2
A path name of a directory to be compared.
.El
.Pp
If only one of
.Ar file1
and
.Ar file2
is a directory,
.Nm
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
See
.Xr largefile 7
for the description of the behavior of
.Nm
when encountering files greater than or equal to 2 Gbyte
.Pq  2^31 bytes .
.Sh FILES
.Bl -tag -width Ds
.It Pa /tmp/d?????
temporary file used for comparison
.It Pa /usr/lib/diffh
executable file for
.Fl h
option
.El
.Sh EXIT STATUS
The following exit values are returned:
.Bl -tag -width Ds
.It 0
No differences were found.
.It 1
Differences were found.
.It >1
An error occurred.
.El
.Sh EXAMPLES
.Sy Example 1 No Typical output of the diff command
.Pp
In the following command,
.Ar dir1
is a directory containing a directory named
.Pa x ,
.Ar dir2
is a directory containing a directory named
.Pa x ,
.Pa dir1/x
and
.Pa dir2/x
both contain files named
.Pa date.out ,
and
.Pa dir2/x
contains a file named
.Pa y :
.Bd -literal -offset 4n
example% diff -r dir1 dir2
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
.Ed
.Sh ENVIRONMENT VARIABLES
See
.Xr environ 7
for descriptions of the following environment variables that affect the
execution of
.Nm :
.Ev LANG ,
.Ev LC_ALL ,
.Ev LC_CTYPE ,
.Ev LC_MESSAGES ,
.Ev LC_TIME ,
and
.Ev NLSPATH .
.Bl -tag -width Ds
.It Ev TZ
Determines the locale for affecting the timezone used for calculating file
timestamps written with the
.Fl C
and
.Fl c
options.
.El
.Sh INTERFACE STABILITY
The command line interface of
.Nm
is
.Sy Committed .
The output of
.Nm
is
.Sy Committed .
.Sh SEE ALSO
.Xr bdiff 1 ,
.Xr cmp 1 ,
.Xr comm 1 ,
.Xr dircmp 1 ,
.Xr ed 1 ,
.Xr pr 1 ,
.Xr sdiff 1 ,
.Xr attributes 7 ,
.Xr environ 7 ,
.Xr largefile 7 ,
.Xr standards 7
.Sh NOTES
Editing scripts produced under the
.Fl e
or
.Fl f
options are na\(:ive about creating lines consisting of a single dot
.Sq \&. .
.Pp
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.