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

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