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