diff.1 (2010 09)

d
diff(1) diff(1)
NAME
diff - differential file and directory comparator
SYNOPSIS
diff [-C n ][-S name ][
-lrs][-bcefhintw] dir1 dir2
diff [-C n ][-S name ][
-bcefhintw] file1 file2
diff [-D string ][-biw
] file1 file2
DESCRIPTION
Comparing Directories
If both arguments are directories,
diff sorts the contents of the directories by name, then runs the reg-
ular file diff algorithm (described below) on text files that have the same name in each directory but
are different. Binary files that differ, common subdirectories, and files that appear in only one directory
are listed. When comparing directories, the following options are recognized:
-l Long output format; each text file
diff is piped through pr to paginate it (see pr(1)).
Other differences are remembered and summarized after all text file differences are
reported.
-r Applies diff recursively to common subdirectories encountered.
-s diff reports files that are identical but otherwise not mentioned.
-S name Starts a directory diff in the middle of the sorted directory, beginning with file
name.
Comparing Files
When run on regular files, and when comparing text files that differ during directory comparison,
diff
tells what lines must be changed in the files to bring them into agreement. diff usually finds a smal-
lest sufficient set of file differences. However, it can be misled by lines containing very few characters or
by other situations. If neither file1 nor file2 is a directory, either can be specified as
-, in which case the
standard input is used. If file1 is a directory, a file in that directory whose filename is the same as the
filename of file2 is used (and vice versa).
There are several options for output format. The default output format contains lines resembling the fol-
lowing:
n1
a n3,n4
n1,n2 d n3
n1,n2 c n3,n4
These lines resemble
ed commands to convert file1 into file2 . The numbers after the letters pertain to
file2. In fact, by exchanging a for d and reading backwards one may ascertain equally how to convert
file2 into file1 .Asined, identical pairs where n1 = n2 or n3 = n4 are abbreviated as a single number.
Following each of these lines come all the lines that are affected in the first file flagged by
<, then all the
lines that are affected in the second file flagged by
>.
Except for
-b, -w, -i,or -t which can be given with any of the others, the following options are mutu-
ally exclusive:
-e Produce a script of a, c, and d commands for the ed editor suitable for recreating file2
from file1. Extra commands are added to the output when comparing directories with -e,
so that the result is a shell script for converting text files common to the two directories
from their state in dir1 to their state in dir2 .
-f Produce a script similar to that of the -e option that is not useful with ed but is more
readable by humans.
-n Produce a script similar to that of -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 (see
rcsdiff(1)).
-c Produce a difference list with 3 lines of context. -c modifies the output format slightly:
the output begins with identification of the files involved, followed by their creation dates,
then each change separated by a line containing about twelve asterisks ( * )s. Lines
removed from file1 are marked with -, and lines added to file2 are marked +. Lines that
change from one file to the other are marked in both files with with !. Changes that lie
HP-UX 11i Version 3: September 2010 1 Hewlett-Packard Company 1

Summary of content (4 pages)