1 .\" $OpenBSD: diff.1,v 1.47 2015/11/24 19:35:41 jmc Exp $
3 .\" Copyright (c) 1980, 1990, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)diff.1 8.1 (Berkeley) 6/30/93
38 .Nd differential file and directory comparator
50 .Op Fl -ignore-all-space
52 .Op Fl -ignore-space-change
55 .Op Fl -no-ignore-file-name-case
58 .Op Fl -show-c-function
60 .Op Fl -speed-large-files
61 .Op Fl -strip-trailing-cr
65 .Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern
66 .Op Fl L Ar label | Fl -label Ar label
70 .Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern
71 .Op Fl L Ar label | Fl -label Ar label
76 .Op Fl -ignore-all-space
78 .Op Fl -ignore-space-change
81 .Op Fl -no-ignore-file-name-case
85 .Op Fl -show-c-function
86 .Op Fl -speed-large-files
88 .Op Fl -strip-trailing-cr
91 .Fl C Ar number | -context Ar number
95 .Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern
100 .Op Fl -ignore-all-space
102 .Op Fl -ignore-space-change
105 .Op Fl -no-ignore-file-name-case
109 .Op Fl -show-c-function
110 .Op Fl -speed-large-files
111 .Op Fl -starting-file
112 .Op Fl -strip-trailing-cr
115 .Fl D Ar string | Fl -ifdef Ar string
119 .Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern
120 .Op Fl L Ar label | Fl -label Ar label
125 .Op Fl -ignore-all-space
127 .Op Fl -ignore-space-change
130 .Op Fl -no-ignore-file-name-case
134 .Op Fl -show-c-function
135 .Op Fl -speed-large-files
136 .Op Fl -starting-file
137 .Op Fl -strip-trailing-cr
140 .Fl U Ar number | Fl -unified Ar number
153 .Op Fl -ignore-all-space
155 .Op Fl -ignore-space-change
159 .Op Fl -no-ignore-file-name-case
164 .Op Fl -report-identical-files
165 .Op Fl -show-c-function
166 .Op Fl -speed-large-files
167 .Op Fl -strip-trailing-cr
170 .Op Fl -unidirectional-new-file
172 .Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern
174 .Op Fl L Ar label | Fl -label Ar label
175 .Op Fl S Ar name | Fl -starting-file Ar name
176 .Op Fl X Ar file | Fl -exclude-from Ar file
177 .Op Fl x Ar pattern | Fl -exclude Ar pattern
183 utility compares the contents of
187 and writes to the standard output the list of changes necessary to
188 convert one file into the other.
189 No output is produced if the files are identical.
191 Output options (mutually exclusive):
196 but produces a diff with
200 Produces a diff with 3 lines of context.
203 the output format is modified slightly:
204 the output begins with identification of the files involved and
205 their creation dates and then each change is separated
206 by a line with fifteen
208 The lines removed from
216 Lines which are changed from one file to the other are marked in
219 Changes which lie within 3 lines of each other are grouped together on
222 Creates a merged version of
226 on the standard output, with C preprocessor controls included so that
227 a compilation of the result without defining
229 is equivalent to compiling
236 Produces output in a form suitable as input for the editor utility,
238 which can then be used to convert file1 into file2.
240 Extra commands are added to the output when comparing directories with
242 so that the result is a
244 script for converting text files which are common to the two directories
250 Identical output to that of the
252 flag, but in reverse order.
253 It cannot be digested by
256 Produces a script similar to that of
258 but in the opposite order and with a count of changed lines on each
259 insert or delete command.
260 This is the form used by
263 Just print a line when the files differ.
264 Does not output a list of changes.
268 but produces a diff with
274 diff with 3 lines of context.
275 A unified diff is similar to the context diff produced by the
280 all lines to be changed (added and/or removed) are present in
293 .Dq Binary files ... differ
294 if files contain binary characters.
295 Use of this option forces
299 Causes trailing blanks (spaces and tabs) to be ignored, and other
300 strings of blanks to compare equal.
302 Try very hard to produce a diff as small as possible.
303 This may consume a lot of processing power and memory when processing
304 large files with many changes.
306 Ignores changes, insertions, and deletions whose lines match the
307 extended regular expression
311 patterns may be specified.
312 All lines in the change must match some pattern for the change to be
316 for more information on regular expression patterns.
318 Ignores the case of letters.
321 will compare equal to
324 Pass the output through
330 instead of the first (and second, if this option is specified twice)
331 file name and time in the context or unified diff header.
333 With unified and context diffs, show with each change
334 the first 40 characters of the last line before the context beginning
335 with a letter, an underscore or a dollar sign.
336 For C source code following standard layout conventions, this will
337 show the prototype of the function the change applies to.
339 Print a tab rather than a space before the rest of the line for the
340 normal, context or unified output formats.
341 This makes the alignment of tabs in the line consistent.
343 Will expand tabs in output lines.
346 output adds character(s) to the front of each line which may screw up
347 the indentation of the original source lines and make the output listing
348 difficult to interpret.
349 This option will preserve the original source's indentation.
353 but causes whitespace (blanks and tabs) to be totally ignored.
355 .Dq if (\ \&a == b \&)
356 will compare equal to
360 Directory comparison options:
363 If a file is found in only one directory, act as if it was found in the
364 other directory too but was of zero size.
366 If a file is found only in
368 act as if it was found in
370 too but was of zero size.
372 Causes application of
374 recursively to common subdirectories encountered.
376 Re-starts a directory
378 in the middle, beginning with file
383 to report files which are the same, which are otherwise not mentioned.
385 Exclude files and subdirectories from comparison whose basenames match
390 options may be specified.
392 Exclude files and subdirectories from comparison whose basenames match
394 Patterns are matched using shell-style globbing via
398 options may be specified.
401 If both arguments are directories,
403 sorts the contents of the directories by name, and then runs the
406 algorithm, producing a change list,
407 on text files which are different.
408 Binary files which differ,
409 common subdirectories, and files which appear in only one directory
410 are described as such.
411 In directory mode only regular files and directories are compared.
412 If a non-regular file such as a device special file or
414 is encountered, a diagnostic message is printed.
422 is applied to the non-directory file and the file contained in
423 the directory file with a filename that is the same as the
424 last component of the non-directory file.
432 the standard input is
442 output contains lines of these forms, where
443 .Va XX , YY , ZZ , QQ
444 are line numbers respective of file order.
446 .Bl -tag -width "XX,YYcZZ,QQ" -compact
447 .It Li XX Ns Ic a Ns Li YY
458 .It Li XX Ns Ic a Ns Li YY,ZZ
459 Same as above, but append the range of lines,
468 .It Li XX Ns Ic d Ns Li YY
475 tells to which line the change would bring
479 .It Li XX,YY Ns Ic d Ns Li ZZ
480 Delete the range of lines
486 .It Li XX Ns Ic c Ns Li YY
495 .It Li XX,YY Ns Ic c Ns Li ZZ
496 Replace the range of specified lines with the line
498 .It Li XX,YY Ns Ic c Ns Li ZZ,QQ
511 subcommands to convert
515 The line numbers before the action letters pertain to
517 those after pertain to
523 and reading the line in reverse order, one can also
524 determine how to convert
531 pairs (where num1 = num2) are abbreviated as a single
534 .Bl -tag -width /tmp/diff.XXXXXXXX -compact
535 .It Pa /tmp/diff. Ns Ar XXXXXXXX
536 Temporary file used when comparing a device or the standard input.
537 Note that the temporary file is unlinked as soon as it is created
538 so it will not show up in a directory listing.
543 utility exits with one of the following values:
545 .Bl -tag -width Ds -offset indent -compact
547 No differences were found.
549 Differences were found.
562 .%A M. Douglas McIlroy
563 .%T "An Algorithm for Differential File Comparison"
564 .%J Computing Science Technical Report
565 .%Q Bell Laboratories 41
571 utility is compliant with the
576 .Op Fl aDdIiLlNnPpqSsTtwXx
577 are extensions to that specification.