BSD 4_3_Tahoe development
[unix-history] / usr / man / cat1 / diffh.0
DIFF(1) UNIX Programmer's Manual DIFF(1)
N\bNA\bAM\bME\bE
diff - differential file and directory comparator
S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS
d\bdi\bif\bff\bf [ -\b-l\bl ] [ -\b-r\br ] [ -\b-s\bs ] [ -\b-c\bce\bef\bfh\bhn\bn ] [ -\b-b\bbi\biw\bwt\bt ] dir1 dir2
d\bdi\bif\bff\bf [ -\b-c\bce\bef\bfh\bhn\bn ]\b] [\b[ -\b-b\bbi\biw\bwt\bt ] file1 file2
d\bdi\bif\bff\bf [ -\b-D\bD_\bs_\bt_\br_\bi_\bn_\bg ] [ -\b-b\bbi\biw\bw ] file1 file2
D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
If both arguments are directories, _\bd_\bi_\bf_\bf sorts the contents
of the directories by name, and then runs the regular file
_\bd_\bi_\bf_\bf algorithm (described below) on text files which are
different. Binary files which differ, common subdirec-
tories, and files which appear in only one directory are
listed. Options when comparing directories are:
-\b-l\bl long output format; each text file _\bd_\bi_\bf_\bf is piped
through _\bp_\br(1) to paginate it, other differences are
remembered and summarized after all text file differ-
ences are reported.
-\b-r\br causes application of _\bd_\bi_\bf_\bf recursively to common sub-
directories encountered.
-\b-s\bs causes _\bd_\bi_\bf_\bf to report files which are the same, which
are otherwise not mentioned.
-\b-S\bSn\bna\bam\bme\be
starts a directory _\bd_\bi_\bf_\bf in the middle beginning with
file _\bn_\ba_\bm_\be.
When run on regular files, and when comparing text files
which differ during directory comparison, _\bd_\bi_\bf_\bf tells what
lines must be changed in the files to bring them into agree-
ment. Except in rare circumstances, _\bd_\bi_\bf_\bf finds a smallest
sufficient set of file differences. If neither _\bf_\bi_\bl_\be_\b1 nor
_\bf_\bi_\bl_\be_\b2 is a directory, then either may be given as `-', in
which case the standard input is used. If _\bf_\bi_\bl_\be_\b1 is a direc-
tory, then a file in that directory whose file-name is the
same as the file-name of _\bf_\bi_\bl_\be_\b2 is used (and vice versa).
There are several options for output format; the default
output format contains lines of these forms:
_\bn_\b1 a _\bn_\b3,_\bn_\b4
_\bn_\b1,_\bn_\b2 d _\bn_\b3
_\bn_\b1,_\bn_\b2 c _\bn_\b3,_\bn_\b4
These lines resemble _\be_\bd commands to convert _\bf_\bi_\bl_\be_\b1 into
_\bf_\bi_\bl_\be_\b2. The numbers after the letters pertain to _\bf_\bi_\bl_\be_\b2. In
fact, by exchanging `a' for `d' and reading backward one may
ascertain equally how to convert _\bf_\bi_\bl_\be_\b2 into _\bf_\bi_\bl_\be_\b1. As in
Printed 7/9/88 May 19, 1986 1
DIFF(1) UNIX Programmer's Manual DIFF(1)
_\be_\bd, identical pairs where _\bn_\b1 = _\bn_\b2 or _\bn_\b3 = _\bn_\b4 are abbreviated
as a single number.
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 `>'.
Except for -\b-b\bb,\b, -\b-w\bw,\b, -\b-i\bi or -\b-t\bt which may be given with any of
the others, the following options are mutually exclusive:
-\b-e\be produces a script of _\ba, _\bc and _\bd commands for the
editor _\be_\bd, which will recreate _\bf_\bi_\bl_\be_\b2 from _\bf_\bi_\bl_\be_\b1.
In connection with -\b-e\be, the following shell program
may help maintain multiple versions of a file.
Only an ancestral file ($1) and a chain of
version-to-version _\be_\bd scripts ($2,$3,...) made by
_\bd_\bi_\bf_\bf need be on hand. A `latest version' appears
on the standard output.
(shift; cat $*; echo '1,$p') | ed - $1
Extra commands are added to the output when compar-
ing directories with -\b-e\be,\b, so that the result is a
_\bs_\bh(1) script for converting text files which are
common to the two directories from their state in
_\bd_\bi_\br_\b1 to their state in _\bd_\bi_\br_\b2.
-\b-f\bf produces a script similar to that of -\b-e\be,\b, not useful
with _\be_\bd, and in the opposite order.
-\b-n\bn produces a script similar to that of -\b-e\be,\b, but in the
opposite order and with a count of changed lines on
each insert or delete command. This is the form
used by _\br_\bc_\bs_\bd_\bi_\bf_\bf(1).
-\b-c\bc produces a diff with lines of context. The default
is to present 3 lines of context and may be
changed, e.g to 10, by -\b-c\bc1\b10\b0. With -\b-c\bc 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
_\bf_\bi_\bl_\be_\b1 are marked with `- '; those added to _\bf_\bi_\bl_\be_\b2
are marked `+ '. Lines which are changed from one
file to the other are marked in both files with
with `! '.
Changes which lie within <context> lines of each
other are grouped together on output. (This is a
change from the previous ``diff -c'' but the
resulting output is usually much easier to inter-
pret.)
Printed 7/9/88 May 19, 1986 2
DIFF(1) UNIX Programmer's Manual DIFF(1)
-\b-h\bh does a fast, half-hearted job. It works only when
changed stretches are short and well separated, but
does work on files of unlimited length.
-\b-D\bDs\bst\btr\bri\bin\bng\bg causes _\bd_\bi_\bf_\bf to create a merged version of _\bf_\bi_\bl_\be_\b1 and
_\bf_\bi_\bl_\be_\b2 on the standard output, with C preprocessor
controls included so that a compilation of the
result without defining _\bs_\bt_\br_\bi_\bn_\bg is equivalent to
compiling _\bf_\bi_\bl_\be_\b1, while defining _\bs_\bt_\br_\bi_\bn_\bg will yield
_\bf_\bi_\bl_\be_\b2.
-\b-b\bb causes trailing blanks (spaces and tabs) to be
ignored, and other strings of blanks to compare
equal.
-\b-w\bw is similar to -\b-b\bb but causes whitespace (blanks and
tabs) to be totally ignored. E.g.,
``if ( a == b )'' will compare equal to
``if(a==b)''.
-\b-i\bi ignores the case of letters. E.g., ``A'' will com-
pare equal to ``a''.
-\b-t\bt will expand tabs in output lines. Normal or -\b-c\bc
output adds character(s) to the front of each line
which may screw up the indentation of the original
source lines and make the output listing difficult
to interpret. This option will preserve the origi-
nal source's indentation.
F\bFI\bIL\bLE\bES\bS
/tmp/d?????
/usr/lib/diffh for -\b-h\bh
/bin/diff for directory diffs
/bin/pr
S\bSE\bEE\bE A\bAL\bLS\bSO\bO
cmp(1), cc(1), comm(1), ed(1), diff3(1)
D\bDI\bIA\bAG\bGN\bNO\bOS\bST\bTI\bIC\bCS\bS
Exit status is 0 for no differences, 1 for some, 2 for trou-
ble.
B\bBU\bUG\bGS\bS
Editing scripts produced under the -\b-e\be or -\b-f\bf option are naive
about creating lines consisting of a single `.\b.'.
When comparing directories with the -\b-b\bb,\b, -\b-w\bw or -\b-i\bi options
specified, _\bd_\bi_\bf_\bf first compares the files ala _\bc_\bm_\bp, and then
decides to run the _\bd_\bi_\bf_\bf algorithm if they are not equal.
This may cause a small amount of spurious output if the
files then turn out to be identical because the only
Printed 7/9/88 May 19, 1986 3
DIFF(1) UNIX Programmer's Manual DIFF(1)
differences are insignificant blank string or case differ-
ences.
Printed 7/9/88 May 19, 1986 4