diff(1) MPE/iX Shell and Utilities diff(1)
______________________________________________________________________
NAME
diff, diffh, bdiff -- compare two text files and show differences
SYNOPSIS
diff [-befHhimnrstw] [-C n] [-c[n]] [-Difname] path1 path2
diffh [-befimnrstw] [-C n] [-c[n]] [-Difname] path1 path2
bdiff [-befimnrstw] [-C n] [-c[n]] [-Difname] path1 path2 [n]
DESCRIPTION
The diff command attempts to determine the minimal set of changes
needed to convert a file named path1 into path2.
If either (but only one) file name is -, diff reads from standard
input. If exactly one of path1 or path2 is a directory, diff
uses a file in that directory with the same name as the other
file name. If both are directories, diff compares files with the
same file names under the two directories; however, it does not
compare files in subdirectories unless you specify the -r option.
When comparing two directories, diff does not compare block spe-
cial files, character special files, or FIFO special files to any
other files and does not compare regular files to directories.
By default, output consists of descriptions of the changes in a
style reminiscent of the ed text editor. A line indicating the
type of change is given. The three types are a (append), d
(delete), and c (change). The output is symmetric in the sense
that a delete in path1 is the counterpart of an append in path2.
diff prefixes each operation with a line number (or range) in
path1 and suffixes each with a line number (or range) in path2.
After the line giving the type of change, diff displays the
deleted or added lines, prefixing lines from path1 with < and
lines from path2 with >.
When you call the command as diffh, it automatically uses the -h
option.
When you call it as bdiff, diff computes the differences in
chunks of n lines (default 3999). This lets you process arbi-
trarily large files and generally produces less output than the
-h option.
Options
diff accepts the following options:
-b ignores white space preceding the newline at the end of each
line and considers strings of white space elsewhere in input
lines to be equivalent. For example if one file contained a
string of three spaces and a tab at a given location while
the other file contained a string of two spaces at the same
location, diff would not report this as a difference.
-C n is equivalent to -cn.
1
diff(1) MPE/iX Shell and Utilities diff(1)
______________________________________________________________________
-c[n]
shows n lines of context before and after each change. The
default value for n is 3. diff marks lines removed from
path1 with -, lines added to path2 with + and lines changed
in both files with !.
-Difname
displays output that is the appropriate input to the C
preprocessor to generate the contents of path2 when ifname
is defined, and the contents of path1 when ifname is not
defined.
-e writes out a script of commands for the ed text editor,
which converts path1 to path2. diff sends the output to the
standard output.
-f writes a script similar to the one produced under -e to the
standard output, but does not adjust the line numbers to
reflect earlier editing changes; instead, they correspond to
the line numbers in path1.
-H uses the half-hearted (-h) algorithm only if the normal
algorithm runs out of system resources.
-h uses a fast, half-hearted algorithm instead of the normal
diff algorithm. This algorithm can handle arbitrarily large
files; however, it is not particularly good at finding a
minimal set of differences in files with many differences.
-i ignores the case of letters when doing the comparison.
-m produces the contents of path2 with extra formatter request
lines interspersed to show which lines were added (those
with vertical line characters in the right margin)
and deleted (indicated by a * in the right margin). These
are nroff/troff requests.
-n displays the differences in a form that is usable by RCS.
-r compares corresponding files under the directories, and
recursively compares corresponding files under corresponding
subdirectories under the directories. You can use this
option when you specify two directory names on the command
line.
-s compares two directories, file by file, and prints messages
for identical files between the two directories.
-t expands tabs into spaces before doing the comparison. diff
sets tab stops every eight columns, for example columns 1,
9, 17.
2
diff(1) MPE/iX Shell and Utilities diff(1)
______________________________________________________________________
-w ignores white space when making the comparison.
EXAMPLES
The following example illustrates the effect of the -c option on
the output of the diff command. The following two files, price1
and price2, are compared with and without the use of the -c
option.
The contents of price1 are as follows:
Company X Price List:
$ 0.39 -- Package of Groat Clusters
$ 5.00 -- Candy Apple Sampler Pack
$ 12.00 -- Box of Crunchy Frog Chocolates
$ 15.99 -- Instant Rain (Just Add Water)
$ 20.00 -- Asparagus Firmness Meter
$ 25.00 -- Package of Seeds for 35 Herbs
$ 30.00 -- Child's Riding Hood (Red)
$ 35.00 -- Genuine Placebos
$ 45.00 -- Case of Simulated Soy Bean Oil
$ 75.88 -- No-Name Contact Lenses
$ 99.99 -- Kiddie Destructo-Bot
$125.00 -- Emperor's New Clothes
The contents of price2 are as follows:
Company X Price List:
$ 0.39 -- Package of Groat Clusters
$ 5.49 -- Candy Apple Sampler Pack
$ 12.00 -- Box of Crunchy Frog Chocolates
$ 15.99 -- Instant Rain (Just Add Water)
$ 17.00 -- Simulated Naugahyde cleaner
$ 20.00 -- Asparagus Firmness Meter
$ 25.00 -- Package of Seeds for 35 Herbs
$ 30.00 -- Child's Riding Hood (Red)
$ 35.00 -- Genuine Placebos
$ 45.00 -- Case of Simulated Soy Bean Oil
$ 75.88 -- No-Name Contact Lenses
$ 99.99 -- Kiddie Destructo-Bot
The command
diff price1 price2
results in the following output:
3
diff(1) MPE/iX Shell and Utilities diff(1)
______________________________________________________________________
4c4
< $ 5.00 -- Candy Apple Sampler Pack
---
> $ 5.49 -- Candy Apple Sampler Pack
6a7
> $ 17.00 -- Simulated Naugahyde cleaner
14d14
< $125.00 -- Emperor's New Clothes
The addition of the -c option, as in
diff -c price1 price2
results in the following output:
*** price1 Wed Mar 04 10:08:40 1992
--- price2 Wed Mar 04 10:09:10 1992
***************
*** 1,9 ****
Company X Price List:
$ 0.39 -- Package of Groat Clusters
! $ 5.00 -- Candy Apple Sampler Pack
$ 12.00 -- Box of Crunchy Frog Chocolates
$ 15.99 -- Instant Rain (Just Add Water)
$ 20.00 -- Asparagus Firmness Meter
$ 25.00 -- Package of Seeds for 35 Herbs
$ 30.00 -- Child's Riding Hood (Red)
--- 1,10 ----
Company X Price List:
$ 0.39 -- Package of Groat Clusters
! $ 5.49 -- Candy Apple Sampler Pack
$ 12.00 -- Box of Crunchy Frog Chocolates
$ 15.99 -- Instant Rain (Just Add Water)
+ $ 17.00 -- Simulated Naugahyde cleaner
$ 20.00 -- Asparagus Firmness Meter
$ 25.00 -- Package of Seeds for 35 Herbs
$ 30.00 -- Child's Riding Hood (Red)
***************
*** 11,14 ****
$ 45.00 -- Case of Simulated Soy Bean Oil
$ 75.88 -- No-Name Contact Lenses
$ 99.99 -- Kiddie Destructo-Bot
- $125.00 -- Emperor's New Clothes
--- 12,14 ----
diff -c marks lines removed from price1 with -, lines added to
price1 with + and lines changed in both files with !. In the
example, diff shows the default 3 lines of context around each
4
diff(1) MPE/iX Shell and Utilities diff(1)
______________________________________________________________________
changed line. One line was changed in both files (marked with !),
one line was added to price1 (marked with +), and one line was
removed from price1 (marked with -).
Note: If there are no marks to be shown in the corresponding
lines of the file being compared, the lines are not displayed.
Lines 12 to 14 of price2 are suppressed for this reason.
DIAGNOSTICS
Possible exit status values are:
0 No differences between the files compared.
1 diff compared the files and found them to be different.
2 An error occurred.
4 At least one of the files is a binary file, containing embed-
ded NUL (\0) bytes or newlines which are more than LINE_MAX
characters apart.
Messages
Message: cannot open directory "pathname"
Cause: You do not have read permission on pathname.
Action: Use chmod to acquire read permission on pathname.
Message: File file1 is a type1 while file file2 is a type2
Cause: The two files specified on the directory were of dif-
ferent file types.
diff can only compare files that have the same file
type.
Action: Specify two files that have the same file type.
Message: file "filename" is binary
Cause: You specified the binary file filename as a diff input
file. diff only works on text files.
Action: Only specify text files as diff input files.
Message: file "filename": line too long: limit num
Cause: The input line is too long.
Action: Try again with a shorter input line.
5
diff(1) MPE/iX Shell and Utilities diff(1)
______________________________________________________________________
Message: "filename": system error
Cause: See syserror(3).
Action: See syserror(3).
Message: files too large, trying "-h" option ...
Cause: You specified the -H option, but there were not enough
free system resources to handle the files. diff will
now try to compare the files using the -h option.
Action: If you are comparing these two files again, specify the
-h option on the command line for faster operation.
Message: insufficient memory
Cause: There were not enough free system resources for diff to
run, even if it used the -h option.
Action: Free up more system resources.
Message: insufficient memory (try diff -h)
Cause: diff ran out of system resources when generating the
data structures used in the differencing algorithm (see
LIMITS).
Action: The -h option of diff requires fewer system resources
than the regular diff algorithm. This may allow it to
succeed where the regular algorithm fails.
Message: internal error--cannot create temporary file
Cause: diff was unable to create a working file that it
needed.
Action: Ensure that you either have a /tmp directory or that
the environment contains a variable TMPDIR which names
a directory where diff can store temporary files.
Also, ensure that you have sufficient permissions on
this directory to create a temporary file.
Message: Missing #ifdef symbol after -D
Cause: You did not specify a conditional label on the command
line after the -D option.
Action: Provide a conditional label with the -D option.
Message: Missing number after "option" option
Cause: You specified option but did not specify a number fol-
lowing it.
Action: Specify a number following the option option.
Message: only one file may be "-"
Cause: Only one of the two files being compared may be the
standard input.
Action: Specify - (standard input) as, at most, one of the two
files to be compared.
Message: read error on file "filename": system error
Cause: See syserror(3).
Action: See syserror(3).
6
diff(1) MPE/iX Shell and Utilities diff(1)
______________________________________________________________________
Message: strcoll error, cannot malloc space.
Cause: There are not enough free system resources to allocate
string space.
Action: Free up more resources.
Message: too many lines in file "filename"
Cause: The file filename contained more than the value of the
configuration variable INT_MAX. Without the -h option,
diff cannot handle a file that large.
Action: Use the -h option.
Message: Unknown option "-option"
Cause: You specified an option that is not valid for diff.
Action: Check the DESCRIPTION section of this man page for a
list of valid diff options.
Message: unlink temp file: system error
Cause: See syserror(3).
Action: See syserror(3).
Message: write error on standard output: system error
Cause: See syserror(3).
Action: See syserror(3).
Message: write error on temporary file: system error
Cause: See syserror(3).
Action: See syserror(3).
LIMITS
The longest input line is 1024 bytes. Except under bdiff and -h,
files are limited to INT_MAX lines.
PORTABILITY
POSIX.2. x/OPEN Portability Guide 4.0. All UNIX systems.
The -D, -f, -H, -h, -i, -m, -n, -s, -t, and -w options; the n
argument to the -c option; and the diffh and bdiff versions of
the command are all extensions to the POSIX standard.
MPE/iX NOTES
For information on how the current MPE/iX implementation may
affect the operation of this utility, see Appendix A, MPE/iX
Implementation Considerations.
SEE ALSO
J. W. Hunt, M. D. McIlroy. An Algorithm for Differential File
Comparison in Computing Science Technical Report 41. Bell Tele-
phone Laboratories.
cmp(1), comm(1), diff3(1), patch(1)
7