d

diff(1)

diff(1)

NAME

diff - differential ®le and directory comparator

SYNOPSIS

diff [-Cn ] [-Sname ] [-lrs][-bcefhintw]dir1 dir2 diff [-Cn ] [-Sname ] [-bcefhintw]®le1 ®le2 diff [-Dstring ] [-biw]®le1 ®le2

DESCRIPTION

Comparing Directories

If both arguments are directories, diff sorts the contents of the directories by name, then runs the regular ®le diff algorithm (described below) on text ®les that have the same name in each directory but are different. Binary ®les that differ, common subdirectories, and ®les that appear in only one directory are listed. When comparing directories, the following options are recognized:

-l

Long output format; each text ®le diff is piped through pr to paginate it (see pr(1)).

 

Other differences are remembered and summarized after all text ®le differences are

 

reported.

-r

Applies diff recursively to common subdirectories encountered.

-s

diff reports ®les that are identical but otherwise not mentioned.

-Sname

Starts a directory diff in the middle of the sorted directory, beginning with ®le name.

Comparing Files

When run on regular ®les, and when comparing text ®les that differ during directory comparison, diff tells what lines must be changed in the ®les to bring them into agreement. diff usually ®nds a smallest suf®cient set of ®le differences. However, it can be misled by lines containing very few characters or by other situations. If neither ®le1 nor ®le2 is a directory, either can be speci®ed as -, in which case the standard input is used. If ®le1 is a directory, a ®le in that directory whose ®lename is the same as the ®lename of ®le2 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 ®le1 into ®le2. The numbers after the letters pertain to ®le2. In fact, by exchanging a for d and reading backwards one may ascertain equally how to convert ®le2 into ®le1. As in ed, 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 ®rst ®le ¯agged by <, then all the lines that are affected in the second ®le ¯agged by >.

Except for -b, -w, -i, or -twhich can be given with any of the others, the following options are mutually exclusive:

-eProduce a script of a, c, and d commands for the ed editor suitable for recreating ®le2 from ®le1. Extra commands are added to the output when comparing directories with -e, so that the result is a shell script for converting text ®les common to the two directories from their state in dir1 to their state in dir2 (see sh-bourne(1)

-fProduce a script similar to that of the -eoption that is not useful with ed but is more readable by humans.

-nProduce 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)).

-cProduce a difference list with 3 lines of context. -cmodi®es the output format slightly: the output begins with identi®cation of the ®les involved, followed by their creation dates, then each change separated by a line containing about twelve asterisks ( * )s. Lines removed from ®le1 are marked with -, and lines added to ®le2 are marked +. Lines that change from one ®le to the other are marked in both ®les with with !. Changes that lie within 3 lines of each other in the ®le are grouped together on output.

Section 1178

− 1 −

HP-UX Release 11i: December 2000