The diff command attempts to determine the minimal set of changes needed either to convert a file named path1 into path2 or the group of files indicated by file... into files of the same name found under the directory dir.
Besides normal ASCII text files, diff and its related
utilities also work on UTF-8 files and 16-bit wide Unicode files.
Such files normally begin with
a multiple-byte marker indicating whether the file's contents are Unicode
big-endian, Unicode little-endian, or UTF-8. Such files are detected
automatically by diff; however, when the multiple-byte
marker is missing you can use the
Normally, the output format of these utilities defaults to the format
of the first file it displays unless the
If either (but only one) file name is -, diff
reads that file from the standard input.
If only two path names appear on the command line and 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, diff does not compare files in subdirectories
unless you specify the
If more than two path names appear on the command line, the last path name is assumed to be a directory and the preceding path names to be files. diff then compares each file in the list to a file with the name under the specified directory.
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
When you call it as bdiff, diff
computes the differences in chunks of n lines (default 3999).
This lets you process arbitrarily large files and generally produces less
output than the
uses diffb to compare the files when binary files are detected.
ignores white space at the end of each line (except the newline) and treats all consecutive strings of white space elsewhere in a line as equivalent (effectively, reducing all strings of white space to a single space for the purpose of comparing lines). 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.
shows n lines of context before and after each change. diff marks lines removed from path1 with -, lines added to path2 with + and lines changed in both files with !. This option conflicts with the
-eand -foptions. -c[n]
is equivalent to
-Cn, but n is optional. The default value for n is 3. This option conflicts with the -eand -foptions. -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.
writes out a script of commands for the ed text editor that converts path1 to path2. diff sends the output to the standard output. This option conflicts with the
-m, -c, and -Coptions. -f
writes a script similar to the one produced under
-eto the standard output, but with the command sequence reversed, the command form reversed, and the line-range separator a space, rather than a comma. This option conflicts with the -m, -c, and -Coptions. -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.
ignores the case of letters when doing the comparison.
describes the diff mark to be used in place of the vertical line character (|) when the
-moption is also specified. mark can be any nroff/troff character or string. It can be as simple or complex as you like. For example, specifying mark as 1 causes the diff mark to be the character 1. Specifying \(sq causes it to be an open square and specifying \s+6\fB\d~\u\fP\s0 causes the diff mark to be a bold-faced tilde (~) six points larger in size half a line below the current line.
This option does not change the character used to indicate deleted lines. It remains the asterisk(*).
produces the contents of path2 with extra formatter request lines interspersed to show which lines were added or changed and which were deleted.
If you do not also specify the
-Moption, added, or changed lines are indicated by a vertical line character | in the right margin. If you do specify the -Moption, diff uses the nroff/troff string given as mark to indicated additions or changes. Deleted lines are always indicated with an asterisk (*) in the right margin. -n
displays the differences in a form that is usable by PTC Integrity.
compares corresponding files under the directories, and recursively compares corresponding files under corresponding subdirectories. You can use this option when you specify two directory names on the command line.
compares two directories, file by file, and prints messages for identical files between the two directories.
-U[[[ c][ lb8oa]][ p[ lb8oa]]]
specifies the input format of any file missing the initial multiple-byte marker, the output format produced, or both.
cis specified, the specifiers that follow it apply to the input consumed.
pis specified, the specifiers that follow it apply to the output produced.
cnor pare specified, the remaining -Uspecifiers apply to the input consumed.
cand pare specified, the remaining -Uarguments apply to both input and output.
The remaining specifiers indicate the format of the characters read from input or written to output (as determined by
cand p): llittle-endian 16-bit wide characters bbig-endian 16-bit wide characters 8UTF-8 characters aASCII characters from the ANSI code page oASCII characters from the OEM code page
When multiple format specifiers can be associated with either c or p, the last appropriate one given on the command for each of c and p is used. For example:
is the same as:
When a p specifier is given without a c specifier and format specifiers are given before the p specifier, those format specifiers apply to the input. For example:
is the same as:
When c or p is specified with no format specifies, little endian 16-bit wide characters are used by default for either input or output, as appropriate.
As an alternative to specifying formats for both input and output with the same
-Uoption, you can specify the -Uoption multiple times. For example, the following are identical: -Uca -Upb -Ucapb
-Uspecifiers are actually case-insensitive. For example, the following are all identical in their behavior: -Ucl -UcL -UCl -UCL -w
ignores white space (not including newlines) when making the comparison. For example, the following two lines are equivalent:
a b c d abcd
The following example illustrates the output of the diff
The following two files, price1 and price2, are
compared with and without the use of the
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
diff price1 price2
results in the following output:
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
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 ----
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.
Sets the default output format. Normally the format of the first file read is used as the default output format. The value must be one of those listed in the File Character Formats section of the unicode reference page.
Possible exit status values are:
No differences between the files compared.
diff compared the files and found them to be different.
Failure due to any of the following:
At least one of the files is a binary file containing embedded NUL (\0) bytes.
- file "filename": no such file or directory
The specified filename does not exist. filename was either typed explicitly, or generated by diff from the directory of one file argument and the base name of the other.
- Files file1 and file2 are identical
-soption was specified and the two named files are identical.
- Common subdirectories: name and name
This message appears when diff is comparing the contents of directories, but you have not specified
-r. When diff discovers two subdirectories with the same name, it reports that the directories exist, but it does not try to compare the contents of the two directories.
- Insufficient memory (try diff -h)
diff ran out of memory for generating the data structures used in the file differencing algorithm (see LIMITS). The
-hoption of diff can handle any size of file without running out of memory.
- Internal error--cannot create temporary file
diff was unable to create a working file that it needed. Ensure that you either have a /tmp directory or that the environment contains a variable TMPDIR that names a directory where diff may store temporary files. Also, ensure that there is sufficient file space in this directory.
- Missing #ifdef symbol after -D
You did not specify a conditional label on the command line after the
- Only one file may be "-"
Of the two input files normally found on the command line of diff, only one can be the standard input.
- Too many lines in "filename"
A file of more than the maximum number of lines (see LIMITS) was given to diff.
The longest input line is 8192 on Windows and most UNIX systems.
POSIX.2. x/OPEN Portability Guide 4.0. All UNIX systems. Windows 7. Windows Server 2008 R2. Windows 8. Windows Server 2012. Windows 10. Windows Server 2016.
PTC MKS Toolkit for Power Users
PTC MKS Toolkit for System Administrators
PTC MKS Toolkit for Developers
PTC MKS Toolkit for Interoperability
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
PTC MKS Toolkit 10.1 patch 1 Documentation Build 2.