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
47 .Op Fl -changed-group-format Ar GFMT
51 .Op Fl -ignore-all-space
53 .Op Fl -ignore-space-change
56 .Op Fl -no-ignore-file-name-case
59 .Op Fl -show-c-function
61 .Op Fl -speed-large-files
62 .Op Fl -strip-trailing-cr
66 .Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern
67 .Op Fl L Ar label | Fl -label Ar label
71 .Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern
72 .Op Fl L Ar label | Fl -label Ar label
74 .Op Fl -changed-group-format Ar GFMT
78 .Op Fl -ignore-all-space
80 .Op Fl -ignore-space-change
83 .Op Fl -no-ignore-file-name-case
87 .Op Fl -show-c-function
88 .Op Fl -speed-large-files
90 .Op Fl -strip-trailing-cr
93 .Fl C Ar number | -context Ar number
97 .Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern
99 .Op Fl -changed-group-format Ar GFMT
103 .Op Fl -ignore-all-space
105 .Op Fl -ignore-space-change
108 .Op Fl -no-ignore-file-name-case
112 .Op Fl -show-c-function
113 .Op Fl -speed-large-files
114 .Op Fl -starting-file
115 .Op Fl -strip-trailing-cr
118 .Fl D Ar string | Fl -ifdef Ar string
122 .Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern
123 .Op Fl L Ar label | Fl -label Ar label
125 .Op Fl -changed-group-format Ar GFMT
129 .Op Fl -ignore-all-space
131 .Op Fl -ignore-space-change
134 .Op Fl -no-ignore-file-name-case
138 .Op Fl -show-c-function
139 .Op Fl -speed-large-files
140 .Op Fl -starting-file
141 .Op Fl -strip-trailing-cr
144 .Fl U Ar number | Fl -unified Ar number
153 .Op Fl -changed-group-format Ar GFMT
158 .Op Fl -ignore-all-space
160 .Op Fl -ignore-space-change
164 .Op Fl -no-ignore-file-name-case
169 .Op Fl -report-identical-files
170 .Op Fl -show-c-function
171 .Op Fl -speed-large-files
172 .Op Fl -strip-trailing-cr
175 .Op Fl -unidirectional-new-file
177 .Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern
179 .Op Fl L Ar label | Fl -label Ar label
180 .Op Fl S Ar name | Fl -starting-file Ar name
181 .Op Fl X Ar file | Fl -exclude-from Ar file
182 .Op Fl x Ar pattern | Fl -exclude Ar pattern
188 utility compares the contents of
192 and writes to the standard output the list of changes necessary to
193 convert one file into the other.
194 No output is produced if the files are identical.
196 Output options (mutually exclusive):
198 .It Fl C Ar number Fl -context Ar number
201 but produces a diff with
205 Produces a diff with 3 lines of context.
208 the output format is modified slightly:
209 the output begins with identification of the files involved and
210 their creation dates and then each change is separated
211 by a line with fifteen
213 The lines removed from
221 Lines which are changed from one file to the other are marked in
224 Changes which lie within 3 lines of each other are grouped together on
226 .It Fl D Ar string Fl -ifdef Ar string
227 Creates a merged version of
231 on the standard output, with C preprocessor controls included so that
232 a compilation of the result without defining
234 is equivalent to compiling
241 Produces output in a form suitable as input for the editor utility,
243 which can then be used to convert file1 into file2.
245 Extra commands are added to the output when comparing directories with
247 so that the result is a
249 script for converting text files which are common to the two directories
255 Identical output to that of the
257 flag, but in reverse order.
258 It cannot be digested by
261 Produces a script similar to that of
263 but in the opposite order and with a count of changed lines on each
264 insert or delete command.
265 This is the form used by
268 Just print a line when the files differ.
269 Does not output a list of changes.
270 .It Fl U Ar number Fl -unified Ar number
273 but produces a diff with
279 diff with 3 lines of context.
280 A unified diff is similar to the context diff produced by the
285 all lines to be changed (added and/or removed) are present in
298 .Dq Binary files ... differ
299 if files contain binary characters.
300 Use of this option forces
304 Causes trailing blanks (spaces and tabs) to be ignored, and other
305 strings of blanks to compare equal.
307 Try very hard to produce a diff as small as possible.
308 This may consume a lot of processing power and memory when processing
309 large files with many changes.
310 .It Fl I Ar pattern Fl -ignore-matching-lines Ar pattern
311 Ignores changes, insertions, and deletions whose lines match the
312 extended regular expression
316 patterns may be specified.
317 All lines in the change must match some pattern for the change to be
321 for more information on regular expression patterns.
322 .It Fl i -ignore-case
323 Ignores the case of letters.
326 will compare equal to
329 Pass the output through
332 .It Fl L Ar label Fl -label Ar label
335 instead of the first (and second, if this option is specified twice)
336 file name and time in the context or unified diff header.
337 .It Fl p -show-c-function
338 With unified and context diffs, show with each change
339 the first 40 characters of the last line before the context beginning
340 with a letter, an underscore or a dollar sign.
341 For C source code following standard layout conventions, this will
342 show the prototype of the function the change applies to.
343 .It Fl T -initial-tab
344 Print a tab rather than a space before the rest of the line for the
345 normal, context or unified output formats.
346 This makes the alignment of tabs in the line consistent.
347 .It Fl t -expand-tabs
348 Will expand tabs in output lines.
351 output adds character(s) to the front of each line which may screw up
352 the indentation of the original source lines and make the output listing
353 difficult to interpret.
354 This option will preserve the original source's indentation.
355 .It Fl w -ignore-all-blanks
357 .Fl b -ignore-space-change
358 but causes whitespace (blanks and tabs) to be totally ignored.
360 .Dq if (\ \&a == b \&)
361 will compare equal to
363 .It Fl -changed-group-format Ar GFMT
364 Format input groups in the provided
366 the format is a string with special keywords:
373 .It Fl -ignore-file-name-case
374 ignore case when comparing file names
375 .It Fl -no-ignore-file-name-case
376 do not ignore case wen comparing file names (default)
379 .It Fl -speed-large-files
380 stub option for compatibility with GNU diff
381 .It Fl -strip-trailing-cr
382 strip carriage return on input files
383 .It Fl tabsize Ar number
384 Number of spaces representing a tab (default 8)
387 Directory comparison options:
390 If a file is found in only one directory, act as if it was found in the
391 other directory too but was of zero size.
392 .It Fl P -unidirectional-new-file
393 If a file is found only in
395 act as if it was found in
397 too but was of zero size.
399 Causes application of
401 recursively to common subdirectories encountered.
402 .It Fl S Ar name Fl -starting-file Ar name
403 Re-starts a directory
405 in the middle, beginning with file
407 .It Fl s -report-identical-files
410 to report files which are the same, which are otherwise not mentioned.
411 .It Fl X Ar file Fl -exclude-from Ar file
412 Exclude files and subdirectories from comparison whose basenames match
417 options may be specified.
418 .It Fl x Ar pattern Fl -exclude Ar pattern
419 Exclude files and subdirectories from comparison whose basenames match
421 Patterns are matched using shell-style globbing via
425 options may be specified.
428 If both arguments are directories,
430 sorts the contents of the directories by name, and then runs the
433 algorithm, producing a change list,
434 on text files which are different.
435 Binary files which differ,
436 common subdirectories, and files which appear in only one directory
437 are described as such.
438 In directory mode only regular files and directories are compared.
439 If a non-regular file such as a device special file or
441 is encountered, a diagnostic message is printed.
449 is applied to the non-directory file and the file contained in
450 the directory file with a filename that is the same as the
451 last component of the non-directory file.
459 the standard input is
469 output contains lines of these forms, where
470 .Va XX , YY , ZZ , QQ
471 are line numbers respective of file order.
473 .Bl -tag -width "XX,YYcZZ,QQ" -compact
474 .It Li XX Ns Ic a Ns Li YY
485 .It Li XX Ns Ic a Ns Li YY,ZZ
486 Same as above, but append the range of lines,
495 .It Li XX Ns Ic d Ns Li YY
502 tells to which line the change would bring
506 .It Li XX,YY Ns Ic d Ns Li ZZ
507 Delete the range of lines
513 .It Li XX Ns Ic c Ns Li YY
522 .It Li XX,YY Ns Ic c Ns Li ZZ
523 Replace the range of specified lines with the line
525 .It Li XX,YY Ns Ic c Ns Li ZZ,QQ
538 subcommands to convert
542 The line numbers before the action letters pertain to
544 those after pertain to
550 and reading the line in reverse order, one can also
551 determine how to convert
558 pairs (where num1 = num2) are abbreviated as a single
561 .Bl -tag -width /tmp/diff.XXXXXXXX -compact
562 .It Pa /tmp/diff. Ns Ar XXXXXXXX
563 Temporary file used when comparing a device or the standard input.
564 Note that the temporary file is unlinked as soon as it is created
565 so it will not show up in a directory listing.
570 utility exits with one of the following values:
572 .Bl -tag -width Ds -offset indent -compact
574 No differences were found.
576 Differences were found.
590 .%A M. Douglas McIlroy
591 .%T "An Algorithm for Differential File Comparison"
592 .%J Computing Science Technical Report
593 .%Q Bell Laboratories 41
599 utility is compliant with the
604 .Op Fl aDdIiLlNnPpqSsTtwXx
605 are extensions to that specification.