[BACK]Return to diff.1 CVS log [TXT][DIR] Up to [local] / src / usr.bin / diff

Annotation of src/usr.bin/diff/diff.1, Revision 1.19

1.19    ! otto        1: .\" $OpenBSD: diff.1,v 1.18 2003/07/22 01:23:51 millert 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.19    ! otto       40: .Op Fl abdilqtTw
1.6       millert    41: .Oo
                     42: .Fl c | Fl e | Fl f |
1.9       millert    43: .Fl n | Fl u
1.6       millert    44: .Oc
1.16      millert    45: .Op Fl L Ar label
1.6       millert    46: .Ar file1 file2
                     47: .Nm diff
1.19    ! otto       48: .Op Fl abdilqtTw
1.16      millert    49: .Op Fl L Ar label
                     50: .Fl C Ar number
1.6       millert    51: .Ar file1 file2
                     52: .Nm diff
1.19    ! otto       53: .Op Fl abdilqtw
1.16      millert    54: .Fl D Ar string
1.1       deraadt    55: .Ar file1 file2
                     56: .Nm diff
1.19    ! otto       57: .Op Fl abdilqtTw
1.16      millert    58: .Op Fl L Ar label
                     59: .Fl U Ar number
1.1       deraadt    60: .Ar file1 file2
                     61: .Nm diff
1.19    ! otto       62: .Op Fl abdilNqtTw
1.6       millert    63: .Oo
                     64: .Fl c | Fl e | Fl f |
1.9       millert    65: .Fl n | Fl u
1.6       millert    66: .Oc
1.11      millert    67: .Bk -words
1.16      millert    68: .Op Fl L Ar label
1.1       deraadt    69: .Op Fl r
                     70: .Op Fl s
1.6       millert    71: .Op Fl S Ar name
1.11      millert    72: .Op Fl X Ar file
                     73: .Op Fl x Ar pattern
                     74: .Ek
1.1       deraadt    75: .Ar dir1 dir2
                     76: .Sh DESCRIPTION
                     77: The
1.5       jmc        78: .Nm
1.1       deraadt    79: utility compares the contents of
                     80: .Ar file1
                     81: and
                     82: .Ar file2
                     83: and writes to the standard output the list of changes necessary to
                     84: convert one file into the other.
                     85: No output is produced if the files are identical.
                     86: .Pp
                     87: Output options (mutually exclusive):
1.2       deraadt    88: .Bl -tag -width Ds
                     89: .It Fl c
1.6       millert    90: Produces a diff with 3 lines of context.
1.1       deraadt    91: With
                     92: .Fl c
                     93: the output format is modified slightly:
                     94: the output beginning with identification of the files involved and
                     95: their creation dates and then each change is separated
                     96: by a line with a dozen *'s.
                     97: The lines removed from
                     98: .Ar file1
1.5       jmc        99: are marked with
                    100: .Sq \-\ \& ;
                    101: those added to
1.1       deraadt   102: .Ar file2
1.5       jmc       103: are marked
                    104: .Sq \+\ \& .
                    105: Lines which are changed from one file to the other are marked in
                    106: both files with
                    107: .Sq !\ \& .
1.19    ! otto      108: Changes which lie within 3 lines of each other are grouped together on
        !           109: output.
        !           110: .It Fl d
        !           111: Try very hard to produce a diff as small as possible. This may consume a
        !           112: lot of processing power and memory when processing large files with
        !           113: many changes.
1.2       deraadt   114: .It Fl e
1.5       jmc       115: Produces output in a form suitable as input for the editor utility,
1.1       deraadt   116: .Xr ed 1 ,
                    117: which can then be used to convert file1 into file2.
                    118: .Pp
                    119: Extra commands are added to the output when comparing directories with
                    120: .Fl e ,
                    121: so that the result is a
1.5       jmc       122: .Xr sh 1
1.1       deraadt   123: script for converting text files which are common to the two directories
                    124: from their state in
                    125: .Ar dir1
                    126: to their state in
                    127: .Ar dir2 .
1.2       deraadt   128: .It Fl f
1.5       jmc       129: Identical output to that of the
1.1       deraadt   130: .Fl e
1.5       jmc       131: flag, but in reverse order.
                    132: It cannot be digested by
1.1       deraadt   133: .Xr ed 1 .
1.2       deraadt   134: .It Fl n
1.5       jmc       135: Produces a script similar to that of
1.1       deraadt   136: .Fl e ,
                    137: but in the opposite order and with a count of changed lines on each
1.5       jmc       138: insert or delete command.
                    139: This is the form used by
                    140: .Xr rcsdiff 1 .
1.13      millert   141: .It Fl q
                    142: Just print a line when the files differ.
                    143: Does not output a list of changes.
1.6       millert   144: .It Fl u
                    145: Produces a
                    146: .Em unified
                    147: diff with 3 lines of context.
                    148: A unified diff is similar to the context diff produced by the
                    149: .Fl c
                    150: option.
                    151: However, unlike with
                    152: .Fl c ,
                    153: all lines to be changed (added and/or removed) are present in
                    154: a single section.
                    155: .It Fl C Ar number
                    156: Like
                    157: .Fl c
                    158: but produces a diff with
                    159: .Ar number
                    160: lines of context.
                    161: .It Fl D Ar string
1.5       jmc       162: Creates a merged version of
1.1       deraadt   163: .Ar file1
                    164: and
                    165: .Ar file2
                    166: on the standard output, with C preprocessor controls included so that
                    167: a compilation of the result without defining
                    168: .Ar string
1.5       jmc       169: is equivalent to compiling
1.1       deraadt   170: .Ar file1 ,
                    171: while defining
                    172: .Ar string
                    173: will yield
                    174: .Ar file2 .
1.6       millert   175: .It Fl U Ar number
                    176: Like
                    177: .Fl u
                    178: but produces a diff with
                    179: .Ar number
                    180: lines of context.
1.2       deraadt   181: .El
1.1       deraadt   182: .Pp
                    183: Comparison options:
1.2       deraadt   184: .Bl -tag -width Ds
1.11      millert   185: .It Fl a
                    186: Treat all files as ASCII.
1.2       deraadt   187: .It Fl b
1.5       jmc       188: Causes trailing blanks (spaces and tabs) to be ignored, and other
1.1       deraadt   189: strings of blanks to compare equal.
1.16      millert   190: .It Fl i
                    191: Ignores the case of letters.
                    192: E.g.,
                    193: .Dq A
                    194: will compare equal to
                    195: .Dq a .
1.14      millert   196: .It Fl l
                    197: Long output format; each text file
                    198: .Nm diff Ns \'d
                    199: is piped through
                    200: .Xr pr 1
                    201: to paginate it;
                    202: other differences are remembered and summarized
                    203: after all text file differences are reported.
1.16      millert   204: .It Fl L Ar label
                    205: Print
                    206: .Ar label
                    207: instead of the first file name and time in the context or unified diff header.
1.2       deraadt   208: .It Fl t
1.5       jmc       209: Will expand tabs in output lines.
                    210: Normal or
1.1       deraadt   211: .Fl c
                    212: output adds character(s) to the front of each line which may screw up
                    213: the indentation of the original source lines and make the output listing
1.5       jmc       214: difficult to interpret.
                    215: This option will preserve the original source's indentation.
1.16      millert   216: .It Fl T
                    217: Print a tab rather than a space before the rest of the line for the
                    218: normal, context or unified output formats.
                    219: This makes the alignment of tabs in the line consistent.
1.2       deraadt   220: .It Fl w
1.5       jmc       221: Is similar to
1.1       deraadt   222: .Fl b
1.5       jmc       223: but causes whitespace (blanks and tabs) to be totally ignored.
                    224: E.g.,
                    225: .Dq if (\ \&a == b \&)
                    226: will compare equal to
                    227: .Dq if(a==b) .
1.2       deraadt   228: .El
1.1       deraadt   229: .Pp
                    230: Directory comparison options:
1.2       deraadt   231: .Bl -tag -width Ds
1.11      millert   232: .It Fl N
                    233: If a file is found in only one directory, act as if it was found in the
                    234: other directory too but was of zero size.
1.12      millert   235: .It Fl P
                    236: If a file is found only in
                    237: .Ar dir2 ,
                    238: act as if it was found in
                    239: .Ar dir1
                    240: too but was of zero size.
1.2       deraadt   241: .It Fl r
1.5       jmc       242: Causes application of
                    243: .Nm
1.1       deraadt   244: recursively to common subdirectories encountered.
1.2       deraadt   245: .It Fl s
1.5       jmc       246: Causes
                    247: .Nm
1.1       deraadt   248: to report files which are the same, which are otherwise not mentioned.
1.6       millert   249: .It Fl S Ar name
1.5       jmc       250: Re-starts a directory
                    251: .Nm
                    252: in the middle, beginning with file
1.1       deraadt   253: .Ar name .
1.11      millert   254: .It Fl X Ar file
                    255: Exclude files and subdirectories from comparison whose basenames match
                    256: lines in
                    257: .Ar file .
                    258: Multiple
                    259: .Fl X
                    260: options may be specified.
                    261: .It Fl x Ar pattern
                    262: Exclude files and subdirectories from comparison whose basenames match
                    263: .Ar pattern .
                    264: Patterns are matched using shell-style globbing via
                    265: .Xr fnmatch 3 .
                    266: Multiple
                    267: .Fl x
                    268: options may be specified.
1.2       deraadt   269: .El
1.1       deraadt   270: .Pp
                    271: If both arguments are directories,
1.5       jmc       272: .Nm
1.1       deraadt   273: sorts the contents of the directories by name, and then runs the
                    274: regular file
1.5       jmc       275: .Nm
1.1       deraadt   276: algorithm, producing a change list,
                    277: on text files which are different.
                    278: Binary files which differ,
                    279: common subdirectories, and files which appear in only one directory
                    280: are described as such.
                    281: .Pp
                    282: If only one of
                    283: .Ar file1
                    284: and
                    285: .Ar file2
                    286: is a directory,
1.5       jmc       287: .Nm
1.1       deraadt   288: is applied to the non-directory file and the file contained in
                    289: the directory file with a filename that is the same as the
                    290: last component of the non-directory file.
                    291: .Pp
1.2       deraadt   292: If either
1.1       deraadt   293: .Ar file1
                    294: or
                    295: .Ar file2
                    296: is
1.2       deraadt   297: .Sq Fl ,
1.1       deraadt   298: the standard input is
                    299: used in its place.
                    300: .Ss Output Style
                    301: The default (without
                    302: .Fl e ,
                    303: .Fl c ,
                    304: or
                    305: .Fl n
1.5       jmc       306: .\" -C
1.1       deraadt   307: options)
                    308: output contains lines of these forms, where
                    309: .Va XX , YY , ZZ , QQ
                    310: are line numbers respective of file order.
                    311: .Pp
1.2       deraadt   312: .Bl -tag -width "XX,YYcZZ,QQ" -compact
                    313: .It Li XX Ns Ic a Ns Li YY
1.1       deraadt   314: At (the end of) line
                    315: .Va XX
                    316: of
                    317: .Ar file1 ,
                    318: append the contents
                    319: of line
                    320: .Va YY
                    321: of
                    322: .Ar file2
                    323: to make them equal.
1.2       deraadt   324: .It Li XX Ns Ic a Ns Li YY,ZZ
1.1       deraadt   325: Same as above, but append the range of lines,
                    326: .Va YY
                    327: through
                    328: .Va ZZ
                    329: of
                    330: .Ar file2
                    331: to line
                    332: .Va XX
                    333: of file1.
1.2       deraadt   334: .It Li XX Ns Ic d Ns Li YY
1.1       deraadt   335: At line
                    336: .Va XX
                    337: delete
1.5       jmc       338: the line.
                    339: The value
1.1       deraadt   340: .Va YY
1.5       jmc       341: tells to which line the change would bring
1.1       deraadt   342: .Ar file1
                    343: in line with
                    344: .Ar file1 .
1.2       deraadt   345: .It Li XX,YY Ns Ic d Ns Li ZZ
1.1       deraadt   346: Delete the range of lines
                    347: .Va XX
                    348: through
                    349: .Va YY
                    350: in
                    351: .Ar file1 .
1.2       deraadt   352: .It Li XX Ns Ic c Ns Li YY
1.1       deraadt   353: Change the line
                    354: .Va XX
                    355: in
                    356: .Ar file1
                    357: to the line
                    358: .Va YY
                    359: in
1.5       jmc       360: .Ar file2 .
1.2       deraadt   361: .It Li XX,YY Ns Ic c Ns Li ZZ
1.1       deraadt   362: Replace the range of specified lines with the line
                    363: .Va ZZ .
1.2       deraadt   364: .It Li XX,YY Ns Ic c Ns Li ZZ,QQ
1.1       deraadt   365: Replace the range
1.2       deraadt   366: .Va XX , Ns YY
1.1       deraadt   367: from
                    368: .Ar file1
                    369: with the range
1.2       deraadt   370: .Va ZZ , Ns QQ
1.1       deraadt   371: from
                    372: .Ar file2 .
1.2       deraadt   373: .El
1.1       deraadt   374: .Pp
                    375: These lines resemble
                    376: .Xr ed 1
                    377: subcommands to convert
                    378: .Ar file1
                    379: into
                    380: .Ar file2 .
                    381: The line numbers before the action letters pertain to
                    382: .Ar file1 ;
                    383: those after pertain to
                    384: .Ar file2 .
                    385: Thus, by exchanging
                    386: .Ic a
                    387: for
                    388: .Ic d
                    389: and reading the line in reverse order, one can also
                    390: determine how to convert
                    391: .Ar file2
                    392: into
                    393: .Ar file1 .
                    394: As in
                    395: .Xr ed 1 ,
                    396: identical
                    397: pairs (where num1 = num2) are abbreviated as a single
                    398: number.
                    399: .Sh ENVIRONMENT
1.2       deraadt   400: .Bl -tag -width TMPDIR
                    401: .It Ev TMPDIR
1.1       deraadt   402: If the environment variable
                    403: .Ev TMPDIR
                    404: exists,
1.5       jmc       405: .Nm
1.2       deraadt   406: will use the directory specified by
1.1       deraadt   407: .Ev TMPDIR
1.2       deraadt   408: as the temporary directory.
                    409: .El
1.1       deraadt   410: .Sh FILES
1.17      millert   411: .Bl -tag -width /tmp/diff.XXXXXXXX -compact
                    412: .It Pa /tmp/diff.XXXXXXXX
                    413: Temporary file used when comparing a device or the standard input.
                    414: Note that the temporary file is unlinked as soon as it is created
                    415: so it will not show up in a directory listing.
1.2       deraadt   416: .El
1.1       deraadt   417: .Sh DIAGNOSTICS
                    418: The
1.5       jmc       419: .Nm
1.1       deraadt   420: utility exits with one of the following values:
1.2       deraadt   421: .Pp
                    422: .Bl -tag -width Ds -compact -offset indent
                    423: .It \&0
1.1       deraadt   424: No differences were found.
1.2       deraadt   425: .It \&1
1.1       deraadt   426: Differences were found.
1.5       jmc       427: .It \*[Gt]\&1
1.1       deraadt   428: An error occurred.
1.2       deraadt   429: .El
1.5       jmc       430: .Sh SEE ALSO
                    431: .Xr cmp 1 ,
                    432: .Xr comm 1 ,
                    433: .Xr diff3 1 ,
1.11      millert   434: .Xr ed 1 ,
1.14      millert   435: .Xr pr 1 ,
1.11      millert   436: .Xr fnmatch 3
1.15      millert   437: .Sh STANDARDS
                    438: The
                    439: .Nm
                    440: utility is expected to be a superset of the
                    441: .St -p1003.1-01
                    442: specification.
1.5       jmc       443: .Sh HISTORY
                    444: A
                    445: .Nm
                    446: command appeared in
                    447: .At v6 .
1.1       deraadt   448: .Sh BUGS
                    449: When comparing directories with the
                    450: .Fl b ,
                    451: .Fl w
                    452: or
                    453: .Fl i
                    454: options specified,
1.5       jmc       455: .Nm
1.1       deraadt   456: first compares the files ala
1.5       jmc       457: .Xr cmp 1 ,
1.1       deraadt   458: and then decides to run the
1.5       jmc       459: .Nm
1.1       deraadt   460: algorithm if they are not equal.
                    461: This may cause a small amount of spurious output if the files
                    462: then turn out to be identical because the only differences are
1.5       jmc       463: insignificant whitespace or case differences.