|DIFF(1)||General Commands Manual||DIFF(1)|
differential file and directory comparator
diff utility compares the contents of
file1 and file2 and writes to
the standard output the list of changes necessary to convert one file into
the other. No output is produced if the files are identical.
Output options (mutually exclusive):
-cbut produces a diff with number lines of context.
-cthe output format is modified slightly: the output begins with identification of the files involved and their creation dates and then each change is separated by a line with fifteen
*'s. The lines removed from file1 are marked with ‘- ’; those added to file2 are marked ‘+ ’. Lines which are changed from one file to the other are marked in both files with ‘! ’. Changes which lie within 3 lines of each other are grouped together on output.
Extra commands are added to the output when comparing
-e, so that the result is a
sh(1) script for converting text files
which are common to the two directories from their state in
dir1 to their state in
-eflag, but in reverse order. It cannot be digested by ed(1).
-e, but in the opposite order and with a count of changed lines on each insert or delete command. This is the form used by rcsdiff(1).
-ubut produces a diff with number lines of context.
-coption. However, unlike with
-c, all lines to be changed (added and/or removed) are present in a single section.
diffwill simply print “Binary files ... differ” if files contain binary characters. Use of this option forces
diffto produce a diff.
-Ipatterns may be specified. All lines in the change must match some pattern for the change to be ignored. See re_format(7) for more information on regular expression patterns.
-coutput 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 preserve the original source's indentation.
-bbut causes whitespace (blanks and tabs) to be totally ignored. E.g., “if ( a == b )” will compare equal to “if(a==b)”.
Directory comparison options:
diffrecursively to common subdirectories encountered.
diffin the middle, beginning with file name.
diffto report files which are the same, which are otherwise not mentioned.
-Xoptions may be specified.
-xoptions may be specified.
If both arguments are directories,
sorts the contents of the directories by name, and then runs the regular
diff algorithm, producing a change list, on
text files which are different. Binary files which differ, common
subdirectories, and files which appear in only one directory are described
as such. In directory mode only regular files and directories are compared.
If a non-regular file such as a device special file or FIFO is encountered,
a diagnostic message is printed.
If only one of file1 and
file2 is a directory,
applied to the non-directory file and the file contained in the directory
file with a filename that is the same as the last component of the
If either file1 or file2 is ‘-’, the standard input is used in its place.
The default (without
-n options) output
contains lines of these forms, where XX,
YY, ZZ, QQ
are line numbers respective of file order.
These lines resemble ed(1)
subcommands to convert file1 into
file2. The line numbers before the action letters
pertain to file1; those after pertain to
file2. Thus, by exchanging
d and reading the line in reverse order, one can
also determine how to convert file2 into
file1. As in ed(1),
identical pairs (where num1 = num2) are abbreviated as a single number.
diff utility exits with one of the
James W. Hunt and M. Douglas McIlroy, An Algorithm for Differential File Comparison, Computing Science Technical Report, Bell Laboratories 41, June 1976.
diff utility is compliant with the
IEEE Std 1003.1-2008 (“POSIX.1”)
The flags [
extensions to that specification.
diff command appeared in
Version 6 AT&T UNIX.
|March 20, 2019||OpenBSD-current|