BSD 4_2 development
[unix-history] / usr / man / man1 / diff.1
CommitLineData
416253bc
C
1.TH DIFF 1 "18 January 1983"
2.UC 4
3.SH NAME
4diff \- differential file and directory comparator
5.SH SYNOPSIS
6.B diff
7[
8.B \-l
9] [
10.B \-r
11] [
12.B \-s
13] [
14\fB\-cefh\fR
15] [
16.B \-b
17] dir1 dir2
18.br
19.B diff
20[
21\fB\-cefh
22] [
23\fB\-b\fR
24] file1 file2
25.br
26.B diff
27[
28.BI \-D string
29] [
30.B \-b
31]
32file1 file2
33.SH DESCRIPTION
34If both arguments are directories,
35.I diff
36sorts the contents of the directories by name, and then runs the
37regular file
38.I diff
39algorithm (described below)
40on text files which are different.
41Binary files which differ,
42common subdirectories, and files which appear in only one directory
43are listed.
44Options when comparing directories are:
45.TP
46.B \-l
47long output format; each text file
48.I diff
49is piped through
50.IR pr (1)
51to paginate it,
52other differences are remembered and summarized
53after all text file differences are reported.
54.TP
55.B \-r
56causes application of
57.I diff
58recursively to common subdirectories encountered.
59.TP
60.B \-s
61causes
62.I diff
63to report files which are the same, which are otherwise not mentioned.
64.TP
65.B \-Sname
66starts a directory
67.I diff
68in the middle beginning with file
69.I name.
70.PP
71When run on regular files, and when comparing text files which differ
72during directory comparison,
73.I diff
74tells what lines must be changed in the files to bring them into agreement.
75Except in rare circumstances,
76.I diff
77finds a smallest sufficient set of file differences.
78If neither
79.I file1
80nor
81.I file2
82is a directory, then either
83may be given as `\-', in which case the standard input is used.
84If
85.I file1
86is a directory,
87then a file in that directory whose file-name is the same as the file-name of
88.I file2
89is used (and vice versa).
90.PP
91There are several options for output format;
92the default output format contains lines of these forms:
93.IP "" 5
94.I n1
95a
96.I n3,n4
97.br
98.I n1,n2
99d
100.I n3
101.br
102.I n1,n2
103c
104.I n3,n4
105.PP
106These lines resemble
107.I ed
108commands to convert
109.I file1
110into
111.IR file2 .
112The numbers after the letters pertain to
113.IR file2 .
114In fact, by exchanging `a' for `d' and reading backward
115one may ascertain equally how to convert
116.I file2
117into
118.IR file1 .
119As in
120.I ed,
121identical pairs where
122.I n1
123=
124.I n2
125or
126.I n3
127=
128.I n4
129are abbreviated as a single number.
130.PP
131Following each of these lines come all the lines that are
132affected in the first file flagged by `<',
133then all the lines that are affected in the second file
134flagged by `>'.
135.PP
136Except for
137.B \-b,
138which may be given with any of the others,
139the following options are mutually exclusive:
140.TP 9
141.B \-e
142producing a script of
143.I "a, c"
144and
145.I d
146commands for the editor
147.I ed,
148which will recreate
149.I file2
150from
151.IR file1 .
152In connection with
153.BR \-e ,
154the following shell program may help maintain
155multiple versions of a file.
156Only an ancestral file ($1) and a chain of
157version-to-version
158.I ed
159scripts ($2,$3,...) made by
160.I diff
161need be on hand.
162A `latest version' appears on
163the standard output.
164.IP
165\ \ \ \ \ \ \ \ (shift; cat $*; echo \'1,$p\') \(bv ed \- $1
166.IP
167Extra commands are added to the output when comparing directories with
168.B \-e,
169so that the result is a
170.IR sh (1)
171script for converting text files which are common to the two directories
172from their state in
173.I dir1
174to their state in
175.I dir2.
176.TP 9
177.B \-f
178produces a script similar to that of
179.B \-e,
180not useful with
181.I ed,
182and in the opposite order.
183.TP 9
184.B \-c
185produces a diff with lines of context.
186The default is to present 3 lines of context and may be changed, e.g to 10, by
187.BR \-c10 \&.
188With
189.B \-c
190the output format is modified slightly:
191the output beginning with identification of the files involved and
192their creation dates and then each change is separated
193by a line with a dozen *'s.
194The lines removed from
195.I file1
196are marked with `\(mi'; those added to
197.I file2
198are marked `+'. Lines which are changed from one
199file to the other are marked in both files with `!'.
200.TP 9
201.B \-h
202does a fast, half-hearted job.
203It works only when changed stretches are short
204and well separated,
205but does work on files of unlimited length.
206.TP
207.B \-Dstring
208causes
209.I diff
210to create a merged version of
211.I file1
212and
213.I file2
214on the standard output, with C preprocessor controls included so that
215a compilation of the result without defining \fIstring\fR is equivalent
216to compiling
217.I file1,
218while defining
219.I string
220will yield
221.I file2.
222.TP
223.B \-b
224causes trailing blanks (spaces and tabs) to be ignored, and other
225strings of blanks to compare equal.
226.SH FILES
227/tmp/d?????
228.br
229/usr/lib/diffh for
230.B \-h
231.br
232/bin/pr
233.SH "SEE ALSO"
234cmp(1), cc(1), comm(1), ed(1), diff3(1)
235.SH DIAGNOSTICS
236Exit status is 0 for no differences, 1 for some, 2 for trouble.
237.SH BUGS
238Editing scripts produced under the
239.BR \-e " or"
240.BR \-f " option are naive about"
241creating lines consisting of a single `\fB.\fR'.
242.PP
243When comparing directories with the
244.B \-b
245option specified,
246.I diff
247first compares the files ala
248.I cmp,
249and then decides to run the
250.I diff
251algorithm if they are not equal.
252This may cause a small amount of spurious output if the files
253then turn out to be identical because the only differences are
254insignificant blank string differences.