DIFF(1) | General Commands Manual | DIFF(1) |
diff
—
differential file and directory comparator
diff |
[-abdipTtw ] [-c |
-e | -f |
-n | -q |
-u ] [-I
pattern] [-L
label] file1 file2 |
diff |
[-abdilpTtw ] [-I
pattern] [-L
label] -C
number file1 file2 |
diff |
[-abdiltw ] [-I
pattern] -D
string file1 file2 |
diff |
[-abdilpTtw ] [-I
pattern] [-L
label] -U
number file1 file2 |
diff |
[-abdilNPprsTtw ] [-c |
-e | -f |
-n | -q |
-u ] [-I
pattern]
[-L label]
[-S name]
[-X file]
[-x pattern]
dir1 dir2 |
The 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):
-C
number-c
but produces a diff with
number lines of context.-c
-c
the 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.-D
string-e
Extra commands are added to the output when comparing
directories with -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
dir2.
-f
-e
flag, but in
reverse order. It cannot be digested by
ed(1).-n
-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).-q
-U
number-u
but produces a diff with
number lines of context.-u
-c
option. However, unlike
with -c
, all lines to be changed (added and/or
removed) are present in a single section.Comparison options:
-a
diff
will
simply print “Binary files ... differ” if files contain
binary characters. Use of this option forces diff
to produce a diff.-b
-d
-I
pattern-I
patterns 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.-i
-L
label-p
-T
-t
-c
output 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.-w
-b
but causes whitespace (blanks and
tabs) to be totally ignored. E.g., “if ( a == b )”
will compare equal to “if(a==b)”.Directory comparison options:
-N
-P
-r
diff
recursively to common
subdirectories encountered.-S
namediff
in the middle,
beginning with file name.-s
diff
to report files which are the same,
which are otherwise not mentioned.-X
file-X
options may be specified.-x
pattern-x
options may be specified.If both arguments are directories, diff
sorts the contents of the directories by name, and then runs the regular
file 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, diff
is
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
non-directory file.
If either file1 or file2 is ‘-’, the standard input is used in its place.
The default (without -e
,
-c
, or -n
options) output
contains lines of these forms, where XX,
YY, ZZ, QQ
are line numbers respective of file order.
XX
a
YY
XX
a
YY,ZZ
XX
d
YY
XX,YY
d
ZZ
XX
c
YY
XX,YY
c
ZZ
XX,YY
c
ZZ,QQ
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 a
for 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.
The diff
utility exits with one of the
following values:
cmp(1), comm(1), diff3(1), ed(1), patch(1), sdiff(1)
James W. Hunt and M. Douglas McIlroy, An Algorithm for Differential File Comparison, AT&T Bell Laboratories, Computing Science Technical Report, 41, June 1976.
The diff
utility is compliant with the
IEEE Std 1003.1-2008 (“POSIX.1”)
specification.
The flags [-aDdIiLlNnPpqSsTtwXx
] are
extensions to that specification.
A diff
command appeared in
Version 5 AT&T UNIX.
March 8, 2021 | OpenBSD-current |