Manual Page Result
0
Command: diff | Section: 1 | Source: UNIX v10 | File: diff.1
DIFF(1) General Commands Manual DIFF(1)
NAME
diff, diff3 - differential file comparison
SYNOPSIS
diff [ option ... ] file1 file2
diff3 [ -ex3 ] file1 file2 file3
DESCRIPTION
When run on regular files diff tells what lines must be changed in the
files to bring them into agreement. Except in rare circumstances, diff
finds a smallest sufficient set of differences. If neither file is a
directory, then one may be meaning the standard input. If one file is
a directory, then a file in that directory with basename the same as
that of the other file is used.
If both files are directories, similarly named files in the two direc-
tories are compared by the method of diff for text files and cmp(1)
otherwise. Options when comparing directories are:
-r Apply diff recursively to similarly named subdirectories.
-s Report files that are the same (normally not mentioned).
There are several options for output format; the default output format
contains lines of these forms:
n1a n3,n4
n1,n2d n3
n1,n2c n3,n4
These lines resemble ed commands to convert file1 into file2. The num-
bers after the letters pertain to file2. In fact, by exchanging for
and reading backward one may ascertain equally how to convert file2
into file1. As in ed, identical pairs where n1=n2 or n3 = n4 are ab-
breviated 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
-e Produce a script of and for ed(1) to recreate file2 from file1.
When comparing directories, produce a sh(1) script to convert
text files common to the two directories.
-cn Include n extra lines of context with each set of differences.
The output format is modified: the output begins with identifi-
cation of the files involved and their creation dates and
changes are separated by lines of *'s. Lines removed from file1
are marked with those added to file2 are marked Lines which are
changed from one file to the other are marked in both files with
-h Do a fast, half-hearted job, useful only when changed stretches
are short and well separated, but does work on files of unlim-
ited length.
-b Ignore trailing blanks (spaces and tabs) and treat other strings
of blanks as if they were a single space.
-B Ignore all blanks.
Diff3 compares three versions of a file and publishes the various dis-
agreeing ranges of text. One of the following indicators introduces
each reported difference.
==== All three files differ.
====f File f differs, where f is 1, 2, or 3.
Disagreeing fragments from the three files follow the ==== line, each
identified by a diff-like range indication:
f:n1a File f lacks text that other files have; their text would be ap-
pended after line n1.
f:n1,n2c
f:n1c Lines n1 through n2 (or line n1 only) of file f would have to be
changed to agree with some other file. The original contents
follow, unless a higher-numbered file has the same contents.
Under option -e, diff3 publishes a script for ed(1) that will incorpo-
rate into file1 all changes between file2 and file3, i.e. the changes
that normally would be flagged ==== and ====3. Option -x (-3) produces
a script to incorporate only changes flagged ==== (====3).
EXAMPLES
(cat diff0-1 diff1-2 diff2-3; echo '1,$p') | ed - file0 >file3
An ancestral has been kept along with a chain of version-to-ver-
sion difference files made thus: The shell command reconstructs
the latest version.
if diff3 mod1 old mod2 | grep -s '^====$'
then :
else (diff3 -e mod1 old mod2; echo '1,$p') | ed - mod1 >new
fi
Compare two different modified versions with an old file. If no
modifications interfere with each other (grep finds no ====
lines), make a new file incorporating both modifications.
FILES
for -h
SEE ALSO
cmp(1), comm(1), ed(1), idiff(1)
DIAGNOSTICS
Diff yields exit status is 0 for no differences, 1 for some, 2 for
trouble.
BUGS
Text lines that consist of a single `.' will defeat options -e, -x, and
-3.
Superfluous output may result for files that differ only in insignifi-
cant blanks when comparing directories under option -b.
Option -c is unpardonably bizarre.
DIFF(1)