SYNOPSIS
diff [-abBiptw] [-cefhnu] [-C number] [-U number] file1 file2
diff [-abBiptw] [-D string] file1 file2
diff [-abBiNptw12] [-cefhnu] [-C number] [-U number] [-lrs] [-S name]
[-x pattern] [-X name] directory1 directory2
DESCRIPTION
Diff tells what lines must be changed in two files to bring them into
agreement. If file1 (file2) is `-', the standard input is used. If
file1 (file2) is a directory, then a file in that directory whose file-
name is the same as the file-name of file2 (file1) is used. The normal
output contains lines of these forms:
n1 a n3,n4
n1,n2 d n3
n1,n2 c 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 `a'
for `d' 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 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 `>'.
-a causes a list of differences to be output for all files, even
for those found to have binary content. This option is an
extension.
-b causes trailing whitespace characters to be ignored, and oth-
er strings of whitespace to compare equal.
-i ignores the case of letters. E.g., ``A'' will compare equal
to ``a''.
-p causes the name of the surrounding C function, or, more ex-
actly, of the first previous unchanged line beginning with a
letter, the dollar sign, or the underscore, to be output with
each set of changes. Implies -c unless -u is also present.
This option is an extension.
-t will expand tabs in output lines. Normal, -c or -u 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 pre-
serve the original source's indentation.
-w is similar to -b but causes whitespace characters to be to-
one file to the other are marked in both files with with `!
'.
-C number Same as -c but uses number of lines of context.
-D string causes diff to create a merged version of file1 and file2 on
the standard output, with C preprocessor controls included so
that a compilation of the result without defining string is
equivalent to compiling file1, while defining string will
yield file2.
-e produces a script of a, c and d commands for the editor ed,
which will recreate file2 from file1. In connection with -e,
the following shell program may help maintain multiple ver-
sions of a file. Only an ancestral file ($1) and a chain of
version-to-version ed scripts ($2,$3,...) made by diff need
be on hand. A `latest version' appears on the standard out-
put.
(shift; cat $*; echo '1,$p') | ed - $1
Extra commands are added to the output when comparing direc-
tories with -e, so that the result is a sh(1) script for con-
verting text files which are common to the two directories
from their state in dir1 to their state in dir2.
-f produces a script similar to that of -e, not useful with ed,
and in the opposite order.
-h 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.
-n produces a script similar to that of -e, but in the opposite
order and with a count of changed lines on each insert or
delete command.
-u produces a unified diff with three lines of context. The
output begins with identification of the files involved and
their creation dates, followed by the changes separated by
`@@ -range +range @@'. Lines removed from file1 are marked
with `-', those added to file2 are marked `+'. This option
is an extension.
-U number Same as -u but uses number of lines of context. This option
is an extension.
If both arguments are directories, diff sorts the contents of the di-
rectories by name, and then runs the regular file diff algorithm on
text files which are different. Binary files which differ, common sub-
directories, and files which appear in only one directory are listed.
-2 is similar to -N, but causes just the text of files that ex-
ist in directory2 only to be output. Files that exist only
in directory1 are listed. This option is an extension.
-r causes application of diff recursively to common subdirecto-
ries encountered.
-s causes diff to report files which are the same, which are
otherwise not mentioned.
-S name starts a directory diff in the middle beginning with file
name.
-x pattern
excludes all file names that match pattern (as described in
glob(7)) from comparison. If pattern matches a directory,
files below that directory are also excluded. This option is
an extension.
-X name excludes all file names contained in name. This option is an
extension.
ENVIRONMENT VARIABLES
LANG, LC_ALL
See locale(7).
LC_CTYPE
Sets the mapping of bytes to characters, character case transla-
tion and the set of whitespace characters.
SYSV3 If this variable is set, invalid options are ignored instead of
being rejected, and the text of some diagnostic messages is
changed.
FILES
/tmp/d?????
/usr/5lib/diffh for -h
diff for directory diffs
pr
SEE ALSO
bdiff(1), cmp(1), cc(1), comm(1), ed(1), diff3(1), patch(1), locale(7)
DIAGNOSTICS
Exit status is 0 for no differences, 1 for some, 2 for trouble.
NOTES
Editing scripts produced under the -e or -f option are naive about cre-
ating lines consisting of a single `.'.
When comparing directories with the -b, -w, or -i options specified,
diff first compares the files ala cmp, and then decides to run the diff
Man(1) output converted with
man2html