diff - Compares text files
diff [-c|-C number|-e|-f|-h|-n] [-bilrstw] [-Sfile] directory1 directory2
diff [-c|-C number|-e|-f|-h|-n] [-bitw] file1 file2
diff [-Dstring] [-bitw] file1 file2
Interfaces documented on this reference page conform to industry standards as follows:
diff: XPG4, XPG4-UNIX
Refer to the
reference page for more information
about industry standards and associated tags.
The -c, -C, -e, -f, -h, and -n options are mutually exclusive.
The -r, -s, and -S options can be specified with directory comparisons only.
The -b, -i, -l, -t, and -w options can be used in combination with any others and in both file and directory comparisons. Causes trailing white space at the end of a line to be treated as a single newline character. Produces a listing with the default number of lines of context (3 lines). The output lists the files being compared and their last modification dates, then lists the differing lines. Lines that are changed from one file to the other are marked in both files with an ! (exclamation point). Changes that lie within the specified number of lines of each other are grouped together on output. Produces output that provides number lines of context (where number is a positive decimal integer). [Compaq] Causes diff to create a merged version of file1 and file2 on the standard output, with C preprocessor controls included. Thus, a compilation of the result without defining string is equivalent to compiling file1, while defining string yields file2. Produces a script of a, c, d, and s commands for the editor ed, which can recreate file2 from file1. In connection with -e, the following shell program can 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.
The path names of files or directories to be compared. See
section for the permissible combinations.
If any operand is specified as
(hyphen), standard input
is read at that point.
If neither file1 nor file2 is a directory, then either can be given as - (dash), in which case the standard input is used. If file1 is a directory and file2 is a file, or vice versa, a file in the specified directory with the same name as the specified file is used.
If both arguments are directories,
contents of the directories by name, and then runs the regular
file algorithm on text files that are different. Binary files
that differ, common subdirectories, and files that appear in only one directory
are also listed.
There are several choices for output format. The default output format contains lines of these forms: number1 a number2,number3 number1,number2 d number3 number1,number2 c number3,number4
These lines resemble ed commands to convert file1 into file2. In these lines, the command a indicates that a line or lines were added to one of the files; d indicates that a line or lines were deleted; and c indicates that a line or lines were changed. The numbers after the letters pertain to file2. In fact, by exchanging a for d and reading backward one can ascertain equally how to convert file2 into file1. As in ed, identical pairs where number1 = number2 or number3 = number4 are abbreviated as a single number.
Following each of these lines come all the lines that are affected in the first file, flagged by < (left angle bracket), then all the lines that are affected in the second file, flagged by > (right angle bracket).
Except in rare circumstances,
finds the smallest
sufficient set of file differences.
[Compaq] Editing scripts produced by the
options cannot create lines consisting of a single .
[Compaq] Block, character, or FIFO special files cannot be
because they cause the command to exit.
[Compaq] If lines at the end of a file are changed and other
output may show this as a delete and
add, as a change, or as a change and add. That is,
is not expected to know what happened.
The following exit values are returned:
An error occurred.
To compare two files, enter: diff chap1.bak chap1
The following environment variables affect the execution of
Provides a default value for the internationalization variables
that are unset or null. If
is unset or null, the corresponding value from the default locale is used.
If any of the internationalization variables contain an invalid setting, the
utility behaves as if none of the variables had been defined.
If set to a non-empty string value, overrides the values of
all the other internationalization variables.
Determines the locale for the interpretation of sequences
of bytes of text data as characters (for example, single-byte as opposed to
multibyte characters in arguments).
Determines the locale for the format and contents of diagnostic
messages written to standard error.
Determines the location of message catalogues for the processing
Determines the locale for affecting the time zone used for
calculating the timestamps written with the
Commands: bdiff(1), cmp(1), comm(1), diff3(1), ed(1), pr(1)