diff(1)
diff --
differential file comparator
Synopsis
diff [-bitw] [-c | -e | -f | -h | -n] filename1 filename2
diff [-bitw] [-C number] filename1 filename2
diff [-bitw] [-D string] filename1 filename2
diff [-bitw] [-c | -e | -f | -h | -n] [-l] [-r] [-s] [-S name]
directory1 directory2
Description
diff tells what lines must be changed in two files to bring them
into agreement.
(It does not use the locale's collation in the
comparison.)
If filename1 (filename2)
is -, the standard input is used.
The LC_CTYPE
environment variable defines the codesets used in the filenames.
If filename1 (filename2)
is a directory, then a file in that directory with the name
filename2 (filename1) is used.
The normal output contains lines of these forms:
n1an3,n4
n1,n2dn3
n1,n2cn3,n4
These lines resemble
ed(1)
commands to convert
filename1
into
filename2.
The numbers after the letters pertain to
filename2.
In fact, by exchanging
a
for
d
and reading backward one may ascertain equally how to convert
filename2
into
filename1.
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 ``>''.
-b-
Ignores trailing blanks (spaces and tabs) and treats
other strings of blanks as equivalent.
The LC_CTYPE
environment variable determines what characters are treated as blanks.
(See
ctype(3C)
and LANG on
environ(5).)
-i-
Ignores the case of letters; for example, ``A'' will be treated as
equal to ``a''.
This option is also influenced by the locale
value in the LC_CTYPE environment variable.
-t-
Expands TAB characters in output lines.
Normal or -c output adds character(s) to the
front of each line that may adversely affect the indentation
of the original source lines and make the output lines difficult
to interpret.
This option will preserve the original source's indentation.
The LC_CTYPE environment variable is used
in correctly formatting the data, and so must specify a locale that
defines the same codesets as used in the input data.
-w-
Ignores all blanks (<Space>
and
TAB
characters)
and treats all other strings of blanks as
equivalent;
for example,
if ( a == b )
will compare equal to
if(a==b).
The following options are mutually exclusive:
-c-
Produces a listing of differences
with three lines of context.
With this option output format is modified slightly:
output begins with identification of the files
involved and their creation dates, then each
change is separated by a line with a dozen
``*''s.
The dates are in the format that output from
date "+%a %b %e %T %Y"
produces. This is affected by the LC_TIME environment variable.
(see
date(1)
and LANG on
environ(5)).
The lines removed from filename1
are marked with '--'; those added to
filename2 are marked '+'.
Lines that are changed from one file to the
other are marked in both files with '!'.
-C number-
Produces a listing of differences identical
to that produced by
-c
with number lines of context.
The form of number
is affected by the LC_NUMERIC environment variable.
(see
strtol(3C)
and LANG on
environ(5)).
-e-
Produces a script of a, c, and d
commands for the editor ed, which will recreate
filename2 from filename1.
In connection with -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 ed
scripts ($2,$3, ...) made by diff
need be on hand.
A ``latest version'' appears on
the standard output.
(shift; cat $; echo '1,$p') | ed - $1
Except in rare circumstances, diff
finds a smallest sufficient set of file
differences.
-f-
Produces a similar script, not useful with ed,
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.
Options -e and -f are unavailable with
-h.
-n-
Produces a script similar to
-e,
but in the opposite order and with a count
of changed lines on each insert or delete
command.
-D string-
Creates a merged version of
filename1 and filename2
with C preprocessor controls
included so that a compilation of the result without
defining string is equivalent to compiling
filename1, while defining string will yield
filename2.
The following options are used for
comparing directories:
-l-
Produce output in long format.
Before the diff, each text file
is piped through
pr(1)
to paginate it.
Other differences
are remembered and summarized after all text file
differences are reported.
-r-
Applies diff recursively to common subdirectories
encountered.
-s-
Reports files that are
identical; these would not otherwise
be mentioned.
-S name-
Starts a directory
diff
in the middle, beginning with the
file name.
Error codes
The exit status returns 0 if no differences are found, 1 if differences
are found, and 2 if an error occurred.
UX:diff: WARNING: Missing newline at end of file X
indicates that the last line of file X did not have a new-line.
If the lines are different, they will be flagged and output;
although the output will seem to indicate they are the same.
Files
/tmp/d?????-
/usr/lib/diffh-
for -h
/usr/bin/pr-
/usr/lib/locale/locale/LC_MESSAGES/uxcore.abi-
language-specific message file
(see LANG on
environ(5)).
References
bdiff(1),
cmp(1),
comm(1),
ed(1),
pr(1)
Notices
Editing scripts produced under the -e or
-f option are naive about
creating lines consisting of a single period (.).
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004