Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ diff(1) — GDT-UNX 6.8_er0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

cmp(1)

cc(1)

comm(1)

ed(1)

diff3(1)

DIFF(1)  —  UNIX Programmer’s Manual

NAME

diff − differential file and directory comparator

SYNOPSIS

diff [ −l ] [ −r ] [ −s ] [ −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 differ.  Binary files which differ, common subdirectories, and files which appear in only one directory are listed.  Options when comparing directories are as follows:

−l Long output format; each text file diff is piped through pr(1) for pagination; other differences are retained in the system and summarized after all text file differences are reported.

−r Causes application of diff recursively to common subdirectories encountered. 

−s Causes diff to report identical files, which are otherwise not mentioned. 

−Sname
Starts a directory diff in the middle beginning with file name. 

When run on regular filefi and comparing text files which differ during directory comparison, diff specifies which lines must be changed in the files to bring them into agreement.  Except in rare circumstances, diff finds the smallest sufficient set of file differences.  If neither file1 nor file2 is a directory, either may be given as ‘−’, in which case, the standard input is used.  If file1 is a directory, a file in that directory with file-name is identical to the file-name of file2 is used (and vice versa). 

There are several options for output format; the default output format contains lines of these forms as follows:

n1 a n3,n4
n1,n2 d n3
n1,n2 c n3,n4

These lines resemble ed commands which convert file1 into file2. The numbers after the letters pertain to file2. By exchanging ‘a’ for ‘d’ and reading backward, one may also ascertain 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 are first the lines affected in the first file flagged by ‘<’, and then all the lines affected in the second file flagged by ‘>’. 

Except for −b, which may be given with any of the other commands, the following options are mutually exclusive:

−e Produces a script of a, c and d commands for the editor ed, which recreates 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,...) created by diff need be available.  A ‘latest version’ appears on the standard output as follows:

        (shift; cat $\(**; echo ´1,$p´) │ ed − $1

Extra commands are added to the output when comparing directories with −e.  The result is a sh(1) script for converting text files common to the two directories from their state in dir1 to their state in dir2. 

−f Produces a script similar to that of −e, but not useful with ed, and in the opposite order. 

−c Produces a diff with lines of context.  Presenting 3 lines of context is the default and may be changed, (e.g., to 10, by −c10).  With −c, the output format is slightly modified; the output begins with identification of the files involved and their creation dates and each change is separated by a line with a dozen \(**’s.  The lines removed from file1 are marked with ‘−’; those lines added to file2 are marked ‘+’.  Lines changed from one file to the other are marked in both files with ‘!’. 

−h Performs a fast, incomplete job.  This command only succeeds when changed stretches are short and well separated, but performs adequately on files of unlimited length. 

−Dstring
Causes diff to create a merged version of file1 and file2 on the standard output.  C preprocessor controls are included so a compilation of the result without defining string is equivalent to compiling file1.  The defining string yields file2. 

−b Causes trailing blanks (spaces and tabs) to be ignored, and other strings of blanks to compare equal. 

FILES

/tmp/d????? 
/usr/lib/diffh for −h
/usr/bin/pr

SEE ALSO

cmp(1), cc(1), comm(1), ed(1), diff3(1)

DIAGNOSTICS

Exit status is 0 for no differences, 1 for some difference, 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 option specified, diff first compares the files ala cmp, and then runs the diff algorithm if the files are not equal.  This may cause a small amount of spurious output if the files are identical because the only differences are insignificant blank string differences. 

4th Berkeley Distribution  —  %W%%Q%%Y%

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