1
0
Files
irix-657m-src/eoe/man/man1/diff.1
2022-09-29 17:59:04 +03:00

381 lines
9.0 KiB
Groff

'\"macro stdmacro
.if n .pH g1.diff @(#)diff 30.3 of 2/3/86
.nr X
.if \nX=0 .ds x} DIFF 1 "Essential Utilities" "\&"
.if \nX=1 .ds x} DIFF 1 "Essential Utilities"
.if \nX=2 .ds x} DIFF 1 "" "\&"
.if \nX=3 .ds x} DIFF "" "" "\&"
.\"
.\" Copyright (c) 1980 Regents of the University of California.
.\" All rights reserved. The Berkeley software License Agreement
.\" specifies the terms and conditions for redistribution.
.\"
.\" @(#)diff.1 6.4 (Berkeley) 5/19/86
.\"
.TH \*(x}
.SH NAME
diff \- differential file and directory comparator
.SH SYNOPSIS
.B diff
[\f3\-lrs\f1]
[\f3\-S\f2name\f1]
[\f3\-cefhn\f1]
[\f3-x\f2pat\f1]
[\f3\-biwt\f1] dir1 dir2
.br
.B diff
[\f3\-cefhn\f1] [\f3\-biwt\f1] file1 file2
.br
.B diff
[\f3\-D\f2string\f1] [\f3\-biw\f1] file1 file2
.br
GNU diff options:
.br
.B diff
[\f3\-#\f1]
[\f3\-aBdHNpqTuv\f1]
[\f3\-C\f2num\f1]
[\f3\-F\f2exp\f1]
[\f3\-I\f2exp\f1]
[\f3\-L\f2lab\f1]
.SH DESCRIPTION
If both arguments are directories,
.I diff
sorts the contents of the directories by name, and then runs the
regular file
.I diff
algorithm (described below)
on text files which are different.
Binary files which differ
(unless
.B -a
is specified),
common subdirectories, and files which appear in only one directory
are listed.
Options when comparing directories are:
.TP
.B \-l
long output format; each text file
.I diff
is piped through
.IR pr (1)
to paginate it,
other differences are remembered and summarized
after all text file differences are reported.
.TP
.B \-r
causes application of
.I diff
recursively to common subdirectories encountered.
.TP
.B \-s
causes
.I diff
to report files which are the same, which are otherwise not mentioned.
.TP
.BI \-S name
starts a directory
.I diff
in the middle beginning with file
.I name.
.TP
.BI \-x pat
adds \f2pat\f1 to a list of regular expressions.
There can be several \f3\-x\f2pat\f1 options.
Any directory or file (base) name matching one of the patterns is skipped.
The special characters available in the pattern
.I pat
are
similar to those used in
.IR egrep (1).
For example, the following command will ignore all "hidden" files and
all RCS archives:
.IP "" 9
diff -r '-x^\\.' '-x,v$' foo bar
.PP
When run on regular files, and when comparing text files which differ
during directory comparison,
.I diff
tells what lines must be changed in the files to bring them into agreement.
Except in rare circumstances,
.I diff
finds a smallest sufficient set of file differences.
If neither
.I file1
nor
.I file2
is a directory, then either
may be given as `\-', in which case the standard input is used.
If
.I file1
is a directory,
then a file in that directory whose file-name is the same as the file-name of
.I file2
is used (and vice versa).
If both
.I file1
and
.I file2
are directories, then files (or files and directories with \f3\-r\f1)
with identical names are compared.
.PP
There are several options for output format;
the default output format contains lines of these forms:
.IP "" 5
.I n1
a
.I n3,n4
.br
.I n1,n2
d
.I n3
.br
.I n1,n2
c
.I n3,n4
.PP
These lines resemble
.I ed
commands to convert
.I file1
into
.IR file2 .
The numbers after the letters pertain to
.IR file2 .
In fact, by exchanging `a' for `d' and reading backward
one may ascertain equally how to convert
.I file2
into
.IR file1 .
As in
.I ed,
identical pairs where
.I n1
=
.I n2
or
.I n3
=
.I 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 `<',
then all the lines that are affected in the second file
flagged by `>'.
.PP
Except for
\f3\-b, -w, -i\fP or \f3-t\fP
which may be given with any of the others,
the following options are mutually exclusive:
.TP 9
.B \-e
produces a script of
.I "a, c"
and
.I d
commands for the editor
.I ed,
which will recreate
.I file2
from
.IR file1 .
In connection with
.BR \-e ,
the following shell program may help maintain
multiple versions of a file.
Only an ancestral file ($1) and a chain of
version-to-version
.I ed
scripts ($2,$3,...) made by
.I diff
need be on hand.
A `latest version' appears on
the standard output.
.IP
\ \ \ \ \ \ \ \ (shift; cat $*; echo \'1,$p\') \(bv ed \- $1
.IP
Extra commands are added to the output when comparing directories with
.B \-e,
so that the result is a
.IR sh (1)
script for converting text files which are common to the two directories
from their state in
.I dir1
to their state in
.I dir2.
.TP 9
.B \-f
produces a script similar to that of
.B \-e,
not useful with
.I ed,
and in the opposite order.
.TP 9
.B \-n
produces a script similar to that of
.B \-e,
but in the opposite order and with a count of changed lines on each
insert or delete command. This is the form used by the RCS commands for
storing a revision change.
.TP 9
.B \-c
produces a diff with 3 lines of context.
Use the
.BI \-C num
option to specify the number of lines.
With
.B \-c
the output format is modified slightly:
the output beginning with identification of the files involved and
their creation dates and then each change is separated
by a line with a dozen *'s.
The lines removed from
.I file1
are marked with `\(mi '; those added to
.I file2
are marked `+ '. Lines which are changed from one
file to the other are marked in both files with `! '.
Changes which lie within <context> lines of each other are grouped
together on output.
.TP 9
.B \-h
has no affect. It is present for
compatibility with
.IR odiff (1).
.TP
.BI \-D string
causes
.I diff
to create a merged version of
.I file1
and
.I file2
on the standard output, with C preprocessor controls included so that
a compilation of the result without defining \f2string\f1 is equivalent
to compiling
.I file1,
while defining
.I string
will yield
.I file2.
.TP 9
.B \-b
causes trailing blanks (spaces and tabs) to be ignored, and other
strings of blanks to compare equal.
.TP 9
.B \-w
is similar to
.B \-b
but causes whitespace (blanks and tabs) to be totally ignored. E.g.,
``if\ (\ a\ ==\ b\ )'' will compare equal to ``if(a==b)''.
.TP 9
.B \-i
ignores the case of letters. E.g., ``A'' will compare equal to ``a''.
.TP 9
.B \-t
will expand tabs in output lines. Normal or
.B \-c
output adds character(s) to the front of each line which may foul up
the indentation of the original source lines and make the output listing
difficult to interpret. This option will preserve the original source's
indentation.
.SH GNU DIFF OPTIONS
.TP 9
.BI \- #
Show
.I #
lines (an integer) of context. This option does not
specify an output format by itself; it has no effect unless it is
combined with
.B -c
or
.BR -u .
.TP 9
.B -a
Treat all files as text and compare them line-by-line, even if they
do not appear to be text
.TP 9
.B -B
Ignore changes that just insert or delete blank lines.
.TP 9
.BI \-C num
Use the context output format, showing \f2lines\f1 (an integer) lines of
context
.TP 9
.B -d
Change the algorithm to find a guaranteed minimal set of changes. This
makes \f1\&\f(CWdiff\f1 slower (sometimes much slower).
.TP 9
.BI \-F exp
In context and unified format, for each hunk of differences, show some
of the last preceding line that matches \f2exp\f1.
.TP 9
.B -H
Use heuristics to speed handling of large files that have numerous
scattered small changes
.TP 9
.BI \-I exp
Ignore changes that just insert or delete lines that match \f2exp\f1.
.TP 9
.BI \-L lab
Use \f2lab\f1 instead of the pathname in the context format
and unified format
headers
.TP 9
.B -N
In directory comparison, if a file is found in only one directory,
treat it as present but empty in the other directory.
.TP 9
.B -p
Show which C function each change is in.
.TP 9
.B -q
Report only whether the files differ, not the details of the
differences.
.TP 9
.B -T
Output a tab rather than a space before the text of a line in normal or
context format. This causes the alignment of tabs in the line to look
normal.
.TP 9
.B -u
Use the unified output format
.TP 9
.B -v
Display the version string.
.LE
.SH FILES
.ta \w'/usr/bin/odiff\ \ \ \ 'u
/usr/bin/odiff executable for \f2odiff\f1.
.br
/bin/diff executable for GNU derived \f2diff\f1.
.br
/bin/pr executed by the \f3-l\f1 option.
.SH "SEE ALSO"
bdiff(1), cc(1), cmp(1), comm(1), odiff(1), diff3(1), ed(1), DIFFsource(5)
.SH DIAGNOSTICS
Exit status is 0 for no differences, 1 for some differences, 2 for trouble.
.SH PERFORMANCE
The GNU derived \f2diff\f1 and older BSD derived \f2odiff\f1
use different algorithms. If the two files to be compared
fit in main memory, then \f2diff\f1 is faster, but if they
don't fit, \f2diff\f1 can cause severe paging. The \f2odiff\f1
algorithm uses a small, fixed amount of memory even on large
files. The multiple pass algorithm of \f2odiff\f1 is up to
two or three times slower than \f2diff\f1, on files that fit
in memory, but can be many times faster on files that don't fit.
.PP
The \f2diff\f1 command automatically invokes the \f2odiff\f1
(searching for \f2odiff\f1 along
.BR $PATH )
on files that
have a combined size larger than one-fourth of memory size,
if no GNU specific \f2diff\f1 options were specified.
If that fails, then \f2diff\f1 silently does the work itself.
.PP
You can force either variant: specifying \f2-H\f1 always gets
\f2diff\f1, specifying \f2odiff\f1 always gets \f2odiff\f1.
.Ee