Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ diff(1) — A/UX 2.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

bdiff(1)

cmp(1)

cpp(1)

comm(1)

diff3(1)

ed(1)




diff(1) diff(1)
NAME diff - differential file and directory comparator SYNOPSIS diff [-l] [-r] [-s] [-Sname] [-cefh] [-b] dir1 dir2 diff [-cefh] [-b] file1 file2 diff [-Dstring] [-b] file1 file2 DESCRIPTION If both arguments are directories, diff sorts the contents of the directories by name, and then runs the regular file diff algorithm (described below) on text files which are different. Binary files which differ, common subdirec- tories, and files which appear in only one directory are listed. Flag options when comparing directories are: -l long output format; each text file diff is piped through pr(1) to paginate it, other differences are remembered and summarized after all text file differ- ences are reported. -r causes application of diff recursively to common sub- directories encountered. -s causes diff to report files which are the same, which are otherwise not mentioned. -Sname starts a directory diff in the middle beginning with file name. When run on regular files, and when comparing text files which differ during directory comparison, diff tells what lines must be changed in the files to bring them into agree- ment. Except in rare circumstances, diff finds a smallest sufficient set of file differences. If neither file1 nor file2 is a directory, then either may be given as ``-'', in which case the standard input is used. If file1 is a direc- tory, then a file in that directory whose filename is the same as the filename of file2 is used (and vice versa). There are several flag options for output format; the de- fault 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 file1 into file2. The numbers after the letters pertain to file2. In April, 1990 1



diff(1) diff(1)
fact, by exchanging a for d and reading backward, one may ascertain equally how to convert file2 into file1. 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 ``>''. Except for -b, which may be given with any of the others, the following flag options are mutually exclusive: -c produces a diff with lines of context. The default is to present 3 lines of context and may be changed, e.g., to 10, by -c10. With -c the output format is modified slightly: the output beginning with identification of the files involved and their creation dates and then each change is separated by a line with a dozen *'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 ``!''. -e producing a script of a, c, and d commands for the editor ed, which will recreate file2 from file1. 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'' ap- pears on the standard output. (shift; cat $*; echo '1,$p') | ed - $1 Extra commands are added to the output when compar- ing 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. Since such a shell script is useful only in a file that you may run on other files, it is best to redirect the output of this command into a file. -f produces a script similar to that of -e, not useful with ed, and in the opposite order. -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. -Dstring causes diff to create a merged version of file1 and 2 April, 1990



diff(1) diff(1)
file2 on the standard output, with C preprocessor controls included so that a compilation of the result without defining string is equivalent to compiling file1, while defining string will yield file2. -b causes trailing blanks (spaces and tabs) to be ig- nored, and other strings of blanks to compare equal. FILES /usr/bin/diff /tmp/d????? /usr/lib/diffh /bin/pr SEE ALSO bdiff(1), cmp(1), cpp(1), comm(1), diff3(1), ed(1). ``Other Tools'' in A/UX Programming Languages and Tools, Volume 2. DIAGNOSTICS Exit status is 0 for no differences, 1 for some, 2 for trou- ble. BUGS Editing scripts produced under the -e or -f flag option are naive about creating lines consisting of a single ``.''. When comparing directories with the -b flag option speci- fied, diff first compares the files as with cmp, and then decides to run the diff algorithm if they are not equal. This may cause a small amount of spurious output if the files then turn out to be identical, because the only differences are insignificant blank string differences. If an unrecognized flag option is specified, diff performs the default operation anyway. diff may not work if files contain a very long line, or if files are very long. April, 1990 3

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026