Annotation of src/usr.bin/diff/diff.1, Revision 1.27
1.27 ! millert 1: .\" $OpenBSD: diff.1,v 1.26 2004/06/20 18:47:45 otto Exp $
1.6 millert 2: .\"
1.2 deraadt 3: .\" Copyright (c) 1980, 1990, 1993
4: .\" The Regents of the University of California. All rights reserved.
1.1 deraadt 5: .\"
1.2 deraadt 6: .\" Redistribution and use in source and binary forms, with or without
7: .\" modification, are permitted provided that the following conditions
8: .\" are met:
9: .\" 1. Redistributions of source code must retain the above copyright
10: .\" notice, this list of conditions and the following disclaimer.
11: .\" 2. Redistributions in binary form must reproduce the above copyright
12: .\" notice, this list of conditions and the following disclaimer in the
13: .\" documentation and/or other materials provided with the distribution.
1.4 deraadt 14: .\" 3. Neither the name of the University nor the names of its contributors
1.2 deraadt 15: .\" may be used to endorse or promote products derived from this software
16: .\" without specific prior written permission.
1.1 deraadt 17: .\"
1.2 deraadt 18: .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19: .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20: .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21: .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22: .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23: .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24: .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25: .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26: .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27: .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28: .\" SUCH DAMAGE.
1.1 deraadt 29: .\"
1.2 deraadt 30: .\" @(#)diff.1 8.1 (Berkeley) 6/30/93
31: .\"
1.16 millert 32: .Dd July 21, 2003
1.1 deraadt 33: .Dt DIFF 1
1.5 jmc 34: .Os
1.1 deraadt 35: .Sh NAME
36: .Nm diff
37: .Nd differential file and directory comparator
38: .Sh SYNOPSIS
39: .Nm diff
1.23 otto 40: .Op Fl abdilpqtTw
1.26 otto 41: .Op Fl I Ar pattern
1.6 millert 42: .Oo
1.26 otto 43: .Fl c | e | f |
44: .Fl n | u
1.6 millert 45: .Oc
1.16 millert 46: .Op Fl L Ar label
1.6 millert 47: .Ar file1 file2
48: .Nm diff
1.23 otto 49: .Op Fl abdilpqtTw
1.26 otto 50: .Op Fl I Ar pattern
1.16 millert 51: .Op Fl L Ar label
52: .Fl C Ar number
1.6 millert 53: .Ar file1 file2
54: .Nm diff
1.19 otto 55: .Op Fl abdilqtw
1.26 otto 56: .Op Fl I Ar pattern
1.16 millert 57: .Fl D Ar string
1.1 deraadt 58: .Ar file1 file2
59: .Nm diff
1.23 otto 60: .Op Fl abdilpqtTw
1.26 otto 61: .Op Fl I Ar pattern
1.16 millert 62: .Op Fl L Ar label
63: .Fl U Ar number
1.1 deraadt 64: .Ar file1 file2
65: .Nm diff
1.23 otto 66: .Op Fl abdilNPpqtTw
1.26 otto 67: .Op Fl I Ar pattern
1.6 millert 68: .Oo
1.26 otto 69: .Fl c | e | f |
70: .Fl n | u
1.6 millert 71: .Oc
1.11 millert 72: .Bk -words
1.16 millert 73: .Op Fl L Ar label
1.1 deraadt 74: .Op Fl r
75: .Op Fl s
1.6 millert 76: .Op Fl S Ar name
1.11 millert 77: .Op Fl X Ar file
78: .Op Fl x Ar pattern
79: .Ek
1.1 deraadt 80: .Ar dir1 dir2
81: .Sh DESCRIPTION
82: The
1.5 jmc 83: .Nm
1.1 deraadt 84: utility compares the contents of
85: .Ar file1
86: and
87: .Ar file2
88: and writes to the standard output the list of changes necessary to
89: convert one file into the other.
90: No output is produced if the files are identical.
91: .Pp
1.22 jmc 92: Output options (mutually exclusive):
1.2 deraadt 93: .Bl -tag -width Ds
94: .It Fl c
1.6 millert 95: Produces a diff with 3 lines of context.
1.1 deraadt 96: With
97: .Fl c
98: the output format is modified slightly:
1.21 jmc 99: the output begins with identification of the files involved and
1.1 deraadt 100: their creation dates and then each change is separated
1.26 otto 101: by a line with fifteen
102: .Li * Ns 's .
1.1 deraadt 103: The lines removed from
104: .Ar file1
1.5 jmc 105: are marked with
1.26 otto 106: .Sq \&-\ \& ;
1.5 jmc 107: those added to
1.1 deraadt 108: .Ar file2
1.5 jmc 109: are marked
110: .Sq \+\ \& .
111: Lines which are changed from one file to the other are marked in
112: both files with
113: .Sq !\ \& .
1.19 otto 114: Changes which lie within 3 lines of each other are grouped together on
115: output.
1.2 deraadt 116: .It Fl e
1.5 jmc 117: Produces output in a form suitable as input for the editor utility,
1.1 deraadt 118: .Xr ed 1 ,
119: which can then be used to convert file1 into file2.
120: .Pp
121: Extra commands are added to the output when comparing directories with
122: .Fl e ,
123: so that the result is a
1.5 jmc 124: .Xr sh 1
1.1 deraadt 125: script for converting text files which are common to the two directories
126: from their state in
127: .Ar dir1
128: to their state in
129: .Ar dir2 .
1.2 deraadt 130: .It Fl f
1.5 jmc 131: Identical output to that of the
1.1 deraadt 132: .Fl e
1.5 jmc 133: flag, but in reverse order.
134: It cannot be digested by
1.1 deraadt 135: .Xr ed 1 .
1.2 deraadt 136: .It Fl n
1.5 jmc 137: Produces a script similar to that of
1.1 deraadt 138: .Fl e ,
139: but in the opposite order and with a count of changed lines on each
1.5 jmc 140: insert or delete command.
141: This is the form used by
142: .Xr rcsdiff 1 .
1.13 millert 143: .It Fl q
144: Just print a line when the files differ.
145: Does not output a list of changes.
1.6 millert 146: .It Fl u
147: Produces a
148: .Em unified
149: diff with 3 lines of context.
150: A unified diff is similar to the context diff produced by the
151: .Fl c
152: option.
153: However, unlike with
154: .Fl c ,
155: all lines to be changed (added and/or removed) are present in
156: a single section.
157: .It Fl C Ar number
158: Like
159: .Fl c
160: but produces a diff with
161: .Ar number
162: lines of context.
163: .It Fl D Ar string
1.5 jmc 164: Creates a merged version of
1.1 deraadt 165: .Ar file1
166: and
167: .Ar file2
168: on the standard output, with C preprocessor controls included so that
169: a compilation of the result without defining
170: .Ar string
1.5 jmc 171: is equivalent to compiling
1.1 deraadt 172: .Ar file1 ,
173: while defining
174: .Ar string
175: will yield
176: .Ar file2 .
1.6 millert 177: .It Fl U Ar number
178: Like
179: .Fl u
180: but produces a diff with
181: .Ar number
182: lines of context.
1.2 deraadt 183: .El
1.1 deraadt 184: .Pp
185: Comparison options:
1.2 deraadt 186: .Bl -tag -width Ds
1.11 millert 187: .It Fl a
1.26 otto 188: Treat all files as
189: .Tn ASCII .
1.2 deraadt 190: .It Fl b
1.5 jmc 191: Causes trailing blanks (spaces and tabs) to be ignored, and other
1.1 deraadt 192: strings of blanks to compare equal.
1.22 jmc 193: .It Fl d
194: Try very hard to produce a diff as small as possible.
195: This may consume a lot of processing power and memory when processing
196: large files with many changes.
1.26 otto 197: .It Fl I Ar pattern
198: Ignores changes, insertions, and deletions whose lines match the
199: extended regular expression
200: .Ar pattern .
201: Multiple
202: .Fl I
203: patterns may be specified.
204: All lines in the change must match some pattern for the change to be
205: ignored.
206: See
207: .Xr re_format 7
208: for more information on regular expression patterns.
1.16 millert 209: .It Fl i
210: Ignores the case of letters.
211: E.g.,
212: .Dq A
213: will compare equal to
214: .Dq a .
1.14 millert 215: .It Fl l
216: Long output format; each text file
217: .Nm diff Ns \'d
218: is piped through
219: .Xr pr 1
220: to paginate it;
221: other differences are remembered and summarized
222: after all text file differences are reported.
1.16 millert 223: .It Fl L Ar label
224: Print
225: .Ar label
1.27 ! millert 226: instead of the first (and second, if this option is specified twice)
! 227: file name and time in the context or unified diff header.
1.23 otto 228: .It Fl p
229: With unified and context diffs, show with each change
230: the first 40 characters of the last line before the context beginning
231: with a letter, an underscore or a dollar sign.
232: For C source code following standard layout conventions, this will
233: show the prototype of the function the change applies to.
1.2 deraadt 234: .It Fl t
1.5 jmc 235: Will expand tabs in output lines.
236: Normal or
1.1 deraadt 237: .Fl c
238: output adds character(s) to the front of each line which may screw up
239: the indentation of the original source lines and make the output listing
1.5 jmc 240: difficult to interpret.
241: This option will preserve the original source's indentation.
1.16 millert 242: .It Fl T
243: Print a tab rather than a space before the rest of the line for the
244: normal, context or unified output formats.
245: This makes the alignment of tabs in the line consistent.
1.2 deraadt 246: .It Fl w
1.5 jmc 247: Is similar to
1.1 deraadt 248: .Fl b
1.5 jmc 249: but causes whitespace (blanks and tabs) to be totally ignored.
250: E.g.,
251: .Dq if (\ \&a == b \&)
252: will compare equal to
253: .Dq if(a==b) .
1.2 deraadt 254: .El
1.1 deraadt 255: .Pp
256: Directory comparison options:
1.2 deraadt 257: .Bl -tag -width Ds
1.11 millert 258: .It Fl N
259: If a file is found in only one directory, act as if it was found in the
260: other directory too but was of zero size.
1.12 millert 261: .It Fl P
262: If a file is found only in
263: .Ar dir2 ,
264: act as if it was found in
265: .Ar dir1
266: too but was of zero size.
1.2 deraadt 267: .It Fl r
1.5 jmc 268: Causes application of
269: .Nm
1.1 deraadt 270: recursively to common subdirectories encountered.
1.2 deraadt 271: .It Fl s
1.5 jmc 272: Causes
273: .Nm
1.1 deraadt 274: to report files which are the same, which are otherwise not mentioned.
1.6 millert 275: .It Fl S Ar name
1.5 jmc 276: Re-starts a directory
277: .Nm
278: in the middle, beginning with file
1.1 deraadt 279: .Ar name .
1.11 millert 280: .It Fl X Ar file
281: Exclude files and subdirectories from comparison whose basenames match
282: lines in
283: .Ar file .
284: Multiple
285: .Fl X
286: options may be specified.
287: .It Fl x Ar pattern
288: Exclude files and subdirectories from comparison whose basenames match
289: .Ar pattern .
290: Patterns are matched using shell-style globbing via
291: .Xr fnmatch 3 .
292: Multiple
293: .Fl x
294: options may be specified.
1.2 deraadt 295: .El
1.1 deraadt 296: .Pp
297: If both arguments are directories,
1.5 jmc 298: .Nm
1.1 deraadt 299: sorts the contents of the directories by name, and then runs the
300: regular file
1.5 jmc 301: .Nm
1.1 deraadt 302: algorithm, producing a change list,
303: on text files which are different.
304: Binary files which differ,
305: common subdirectories, and files which appear in only one directory
306: are described as such.
1.25 millert 307: In directory mode only regular files and directories are compared.
1.26 otto 308: If a non-regular file such as a device special file or
309: .Tn FIFO
310: is encountered, a diagnostic message is printed.
1.1 deraadt 311: .Pp
312: If only one of
313: .Ar file1
314: and
315: .Ar file2
316: is a directory,
1.5 jmc 317: .Nm
1.1 deraadt 318: is applied to the non-directory file and the file contained in
319: the directory file with a filename that is the same as the
320: last component of the non-directory file.
321: .Pp
1.2 deraadt 322: If either
1.1 deraadt 323: .Ar file1
324: or
325: .Ar file2
326: is
1.2 deraadt 327: .Sq Fl ,
1.1 deraadt 328: the standard input is
329: used in its place.
330: .Ss Output Style
331: The default (without
332: .Fl e ,
333: .Fl c ,
334: or
335: .Fl n
1.5 jmc 336: .\" -C
1.1 deraadt 337: options)
338: output contains lines of these forms, where
339: .Va XX , YY , ZZ , QQ
340: are line numbers respective of file order.
341: .Pp
1.2 deraadt 342: .Bl -tag -width "XX,YYcZZ,QQ" -compact
343: .It Li XX Ns Ic a Ns Li YY
1.1 deraadt 344: At (the end of) line
345: .Va XX
346: of
347: .Ar file1 ,
348: append the contents
349: of line
350: .Va YY
351: of
352: .Ar file2
353: to make them equal.
1.2 deraadt 354: .It Li XX Ns Ic a Ns Li YY,ZZ
1.1 deraadt 355: Same as above, but append the range of lines,
356: .Va YY
357: through
358: .Va ZZ
359: of
360: .Ar file2
361: to line
362: .Va XX
363: of file1.
1.2 deraadt 364: .It Li XX Ns Ic d Ns Li YY
1.1 deraadt 365: At line
366: .Va XX
367: delete
1.5 jmc 368: the line.
369: The value
1.1 deraadt 370: .Va YY
1.5 jmc 371: tells to which line the change would bring
1.1 deraadt 372: .Ar file1
373: in line with
374: .Ar file1 .
1.2 deraadt 375: .It Li XX,YY Ns Ic d Ns Li ZZ
1.1 deraadt 376: Delete the range of lines
377: .Va XX
378: through
379: .Va YY
380: in
381: .Ar file1 .
1.2 deraadt 382: .It Li XX Ns Ic c Ns Li YY
1.1 deraadt 383: Change the line
384: .Va XX
385: in
386: .Ar file1
387: to the line
388: .Va YY
389: in
1.5 jmc 390: .Ar file2 .
1.2 deraadt 391: .It Li XX,YY Ns Ic c Ns Li ZZ
1.1 deraadt 392: Replace the range of specified lines with the line
393: .Va ZZ .
1.2 deraadt 394: .It Li XX,YY Ns Ic c Ns Li ZZ,QQ
1.1 deraadt 395: Replace the range
1.26 otto 396: .Va XX , Ns Va YY
1.1 deraadt 397: from
398: .Ar file1
399: with the range
1.26 otto 400: .Va ZZ , Ns Va QQ
1.1 deraadt 401: from
402: .Ar file2 .
1.2 deraadt 403: .El
1.1 deraadt 404: .Pp
405: These lines resemble
406: .Xr ed 1
407: subcommands to convert
408: .Ar file1
409: into
410: .Ar file2 .
411: The line numbers before the action letters pertain to
412: .Ar file1 ;
413: those after pertain to
414: .Ar file2 .
415: Thus, by exchanging
416: .Ic a
417: for
418: .Ic d
419: and reading the line in reverse order, one can also
420: determine how to convert
421: .Ar file2
422: into
423: .Ar file1 .
424: As in
425: .Xr ed 1 ,
426: identical
427: pairs (where num1 = num2) are abbreviated as a single
428: number.
429: .Sh ENVIRONMENT
1.2 deraadt 430: .Bl -tag -width TMPDIR
431: .It Ev TMPDIR
1.1 deraadt 432: If the environment variable
433: .Ev TMPDIR
434: exists,
1.5 jmc 435: .Nm
1.2 deraadt 436: will use the directory specified by
1.1 deraadt 437: .Ev TMPDIR
1.2 deraadt 438: as the temporary directory.
439: .El
1.1 deraadt 440: .Sh FILES
1.17 millert 441: .Bl -tag -width /tmp/diff.XXXXXXXX -compact
1.26 otto 442: .It Pa /tmp/diff. Ns Ar XXXXXXXX
1.17 millert 443: Temporary file used when comparing a device or the standard input.
444: Note that the temporary file is unlinked as soon as it is created
445: so it will not show up in a directory listing.
1.2 deraadt 446: .El
1.1 deraadt 447: .Sh DIAGNOSTICS
448: The
1.5 jmc 449: .Nm
1.1 deraadt 450: utility exits with one of the following values:
1.2 deraadt 451: .Pp
452: .Bl -tag -width Ds -compact -offset indent
453: .It \&0
1.1 deraadt 454: No differences were found.
1.2 deraadt 455: .It \&1
1.1 deraadt 456: Differences were found.
1.5 jmc 457: .It \*[Gt]\&1
1.1 deraadt 458: An error occurred.
1.2 deraadt 459: .El
1.5 jmc 460: .Sh SEE ALSO
461: .Xr cmp 1 ,
462: .Xr comm 1 ,
463: .Xr diff3 1 ,
1.11 millert 464: .Xr ed 1 ,
1.14 millert 465: .Xr pr 1 ,
1.26 otto 466: .Xr fnmatch 3 ,
467: .Xr re_format 7
1.15 millert 468: .Sh STANDARDS
469: The
470: .Nm
471: utility is expected to be a superset of the
1.24 jmc 472: .St -p1003.1-2001
1.15 millert 473: specification.
1.5 jmc 474: .Sh HISTORY
475: A
476: .Nm
477: command appeared in
478: .At v6 .
1.1 deraadt 479: .Sh BUGS
480: When comparing directories with the
481: .Fl b ,
482: .Fl w
483: or
484: .Fl i
485: options specified,
1.5 jmc 486: .Nm
1.1 deraadt 487: first compares the files ala
1.5 jmc 488: .Xr cmp 1 ,
1.1 deraadt 489: and then decides to run the
1.5 jmc 490: .Nm
1.1 deraadt 491: algorithm if they are not equal.
492: This may cause a small amount of spurious output if the files
493: then turn out to be identical because the only differences are
1.5 jmc 494: insignificant whitespace or case differences.