[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.25

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