]> git.lizzy.rs Git - plan9front.git/blob - sys/man/1/diff
audio(1): replace references to juke(7) and playlistfs(7) with zuke(1) (thanks unobe)
[plan9front.git] / sys / man / 1 / diff
1 .TH DIFF 1 
2 .SH NAME
3 diff \- differential file comparator
4 .SH SYNOPSIS
5 .B diff
6 [
7 .B -abcefmnruw
8
9 .I file1 ... file2
10 .SH DESCRIPTION
11 .I Diff
12 tells what lines must be changed in two files to bring them
13 into agreement.
14 If one file
15 is a directory,
16 then a file in that directory with basename the same as that of
17 the other file is used.
18 If both files are directories, similarly named files in the
19 two directories are compared by the method of 
20 .I diff
21 for text
22 files and
23 .IR cmp (1)
24 otherwise.
25 If more than two file names are given, then each argument is compared
26 to the last argument as above.
27 The 
28 .B -r
29 option causes
30 .I diff
31 to process similarly named subdirectories recursively.
32 When processing more than one file, 
33 .I diff
34 prefixes file differences with a single line
35 listing the two differing files, in the form of
36
37 .I diff
38 command line.
39 The
40 .B -m
41 flag causes this behavior even when processing single files.
42 .PP
43 The normal output contains lines of these forms:
44 .IP "" 5
45 .I n1
46 .B a
47 .I n3,n4
48 .br
49 .I n1,n2
50 .B d
51 .I n3
52 .br
53 .I n1,n2
54 .B c
55 .I n3,n4
56 .PP
57 These lines resemble
58 .I ed
59 commands to convert
60 .I file1
61 into
62 .IR file2 .
63 The numbers after the letters pertain to
64 .IR file2 .
65 In fact, by exchanging `a' for `d' and reading backward
66 one may ascertain equally how to convert 
67 .I file2
68 into
69 .IR file1 .
70 As in 
71 .IR ed ,
72 identical pairs where
73 .I n1
74 =
75 .I n2
76 or
77 .I n3
78 =
79 .I n4
80 are abbreviated as a single number.
81 .PP
82 Following each of these lines come all the lines that are
83 affected in the first file flagged by `<', 
84 then all the lines that are affected in the second file
85 flagged by `>'.
86 .PP
87 The
88 .B -b
89 option causes
90 trailing blanks (spaces and tabs) to be ignored
91 and other strings of blanks to compare equal.
92 The
93 .B -w
94 option causes all white-space to be removed from input lines
95 before applying the difference algorithm.
96 .PP
97 The
98 .B -n
99 option prefixes each range with 
100 .IB file : \fR
101 and inserts a space around the 
102 .BR a ,
103 .BR c ,
104 and
105 .B d
106 verbs.
107 The
108 .B -e
109 option produces a script of
110 .I "a, c"
111 and 
112 .I d
113 commands for the editor
114 .IR ed ,
115 which will recreate
116 .I file2
117 from
118 .IR file1 .
119 The
120 .B -f
121 option produces a similar script,
122 not useful with
123 .IR ed ,
124 in the opposite order. It may, however, be
125 useful as input to a stream-oriented post-processor.
126 .PP
127 The
128 .B -c
129 option includes three lines of context around each
130 change, merging changes whose contexts overlap.
131 In this mode,
132 .I diff
133 prints
134 .L -
135 and
136 .L +
137 instead of
138 .L <
139 and
140 .L >
141 because the former are easier to distinguish when mixed.
142 The
143 .B -a
144 flag displays the entire file as context.
145 .PP
146 The
147 .B -u
148 option provides a unix-compatible unified diff.
149 This format is similar to that provided by
150 .BR -c .
151 However, the
152 .L +
153 and
154 .L -
155 prefixes are not separated from the rest of the line by spaces,
156 and the file header is in the following format:
157 .IP
158 .EX
159 --- filename.old
160 +++ filename.new
161 @@ -line,len +line,len @@
162 .EE
163 .PP
164 Except in rare circumstances,
165 .I diff
166 finds a smallest sufficient set of file
167 differences.
168 .SH FILES
169 .B /tmp/diff[12]
170 .SH SOURCE
171 .B /sys/src/cmd/diff
172 .SH "SEE ALSO"
173 .IR cmp (1),
174 .IR comm (1),
175 .IR ed (1),
176 .IR idiff (1)
177 .SH DIAGNOSTICS
178 Exit status is the empty string
179 for no differences,
180 .L some
181 for some, 
182 and
183 .L error
184 for trouble.
185 .SH BUGS
186 Editing scripts produced under the
187 .BR -e " or"
188 .BR -f " option are naive about"
189 creating lines consisting of a single `\fB.\fR'.
190 .PP
191 When running
192 .I diff
193 on directories, the notion of what is a text
194 file is open to debate.