From: CSBVAX::MRGATE!montnaro@steinmetz@SMTP 5-FEB-1988 10:42 To: ARISIA::EVERHART Subj: diff(1) man page, so you can properly interpret context diffs Received: from sprite.steinmetz (sprite.ARPA) by kbsvax.steinmetz (1.2/1.1x Steinmetz) id AA10111; Thu, 4 Feb 88 23:55:28 est Received: by sprite.steinmetz (3.2/1.1x Steinmetz) id AA18165; Thu, 4 Feb 88 23:55:18 EST Date: Thu, 4 Feb 88 23:55:18 EST From: Skip Montanaro Posted-Date: Thu, 4 Feb 88 23:55:18 EST Message-Id: <8802050455.AA18165@sprite.steinmetz> To: everhart@arisia.decnet Subject: diff(1) man page, so you can properly interpret context diffs DIFF(1) USER COMMANDS DIFF(1) NAME diff - show differences between the contents of files or directories SYNOPSIS diff [ -biwt ] [ -c[#] | -e | -f | -n | -h ] filename1 filename2 diff [ -biwt ] [ -Dstring ] filename1 filename2 diff [ -biwt ] [ -c[#] | -e | -f | -n | -h ] [ -l ] [ -r ] [ -s ] [ -Sname ] dir1 dir2 DESCRIPTION diff is a differential file comparator. When run on regular files, and when comparing text files that differ during directory comparison (see the notes below on comparing directories), diff tells what lines must be changed in the files to bring them into agreement. Except in rare cir- cumstances, diff finds a smallest sufficient set of differ- ences. If neither filename1 nor filename2 is a directory, either may be given as -, in which case the standard input is used. If filename1 is a directory, a file in that direc- tory whose filename is the same as the filename of filename2 is used (and vice versa). There are several options for output format; the default output format contains lines of these forms: n1 a n3,n4 n1,n2 d n3 n1,n2 c n3,n4 These lines resemble ed commands to convert filename1 into filename2. The numbers after the letters pertain to filename2. In fact, by exchanging a for d and reading back- ward one may ascertain equally how to convert filename2 into filename1. 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 first file flagged by <, then all the lines that are affected in the second file flagged by >. If both arguments are directories, diff sorts the contents of the directories by name, and then runs the regular file diff program as described above on text files which are dif- ferent. Binary files which differ, common subdirectories, and files which appear in only one directory are listed. OPTIONS -b ignore trailing blanks (spaces and tabs) and treat all other strings of blanks as equivalent. Sun Release 3.4 Last change: 23 September 1985 1 DIFF(1) USER COMMANDS DIFF(1) -w ignore all blanks (spaces and tabs); e.g., ``if ( a == b )'' will compare equal to ``if(a==b)''. -i ignore the case of letters; e.g., ``A'' will compare equal to ``a''. -t expand tabs in output lines. Normal or -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. The following four options are mutually exclusive: -c[#] produces a listing of differences with lines of con- text. The default is to present 3 lines of context and may be changed, (to 10, for example), by -c10. With -c the output format is modified slightly: output begins with identification of the files involved and their creation dates, then each change is separated by a line with a dozen *s. The lines removed from filename1 are marked with - ; those added to filename2 are marked + . Lines which are changed from one file to the other are marked in both files with ! . Changes which lie within lines of each other are grouped together on output. (This is a change from the previous ``diff -c'' but the resulting output is usually much easier to interpret.) -e produce a script of a, c, and d commands for the editor ed, which will recreate filename2 from filename1. In connection with -e, the following shell program may help maintain multiple versions of a file. Only an ancestral file ($1) and a chain of version-to-version ed scripts ($2,$3,...) made by diff need be on hand. A `latest version' appears on the standard output. (shift; cat $*; echo '1,$p') | ed - $1 Extra commands are added to the output when comparing directories with -e, so that the result is a sh script for converting text files which are common to the two directories from their state in dir1 to their state in dir2. -f produce a script similar to that of -e, not useful with ed, which is in the opposite order. -n produce a script similar to that of -e, but in the opposite order and with a count of changed lines on Sun Release 3.4 Last change: 23 September 1985 2 DIFF(1) USER COMMANDS DIFF(1) each insert or delete command. -h does a fast, half-hearted job. It works only when changed stretches are short and well separated, but does work on files of unlimited length. Options for the second form of diff are as follows: -Dstring create a merged version of filename1 and filename2 on the standard output, with C preprocessor controls included so that a compilation of the result without defining string is equivalent to compiling filename1, while defining string will yield filename2. Options when comparing directories are: -l long output format; each text file diff is piped through pr to paginate it, other differences are remem- bered and summarized after all text file differences are reported. -r apply diff recursively to common subdirectories encoun- tered. -s report files which are the same, which are otherwise not mentioned. -Sname starts a directory diff in the middle, beginning with file name. FILES /tmp/d????? /usr/lib/diffh for -h /bin/diff for directory diffs /usr/bin/pr SEE ALSO cmp(1), comm(1), cpp(1), diff3(1V), ed(1) DIAGNOSTICS Exit status is 0 for no differences, 1 for some differences, 2 for trouble. BUGS Editing scripts produced under the -e or -f option are naive about creating lines consisting of a single `.'. When comparing directories with the -b, -w, or -i options specified, diff first compares the files (as in cmp), and then runs the regular diff algorithm if they are not equal. Sun Release 3.4 Last change: 23 September 1985 3 DIFF(1) USER COMMANDS DIFF(1) This may cause a small amount of spurious output if the files then turn out to be identical because the only differ- ences are insignificant blank string or case differences. The -D option ignores existing preprocessor controls in the source files, and can generate #ifdefs's with overlapping scope. The output should be checked by hand, or run through cc -E and then diffed with the original source files. Discrpancies revealed should be corrected before compila- tion. WARNINGS Missing newline at end of file X indicates that the last line of file X did not have a new-line. If the lines are different, they will be flagged and output, although the output will seem to indicate they are the same. Sun Release 3.4 Last change: 23 September 1985 4