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
37 .Nd differential file and directory comparator
46 .Op Fl -color Ns = Ns Ar when
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
63 .Op Fl -tabsize Ar number
66 .Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern
67 .Op Fl F Ar pattern | Fl -show-function-line Ar pattern
68 .Op Fl L Ar label | Fl -label Ar label
72 .Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern
73 .Op Fl F Ar pattern | Fl -show-function-line Ar pattern
74 .Op Fl L Ar label | Fl -label Ar label
76 .Op Fl -color Ns = Ns Ar when
77 .Op Fl -changed-group-format Ar GFMT
81 .Op Fl -ignore-all-space
83 .Op Fl -ignore-space-change
86 .Op Fl -no-ignore-file-name-case
90 .Op Fl -show-c-function
91 .Op Fl -speed-large-files
93 .Op Fl -strip-trailing-cr
94 .Op Fl -tabsize Ar number
96 .Fl C Ar number | -context Ar number
100 .Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern
102 .Op Fl -color Ns = Ns Ar when
103 .Op Fl -changed-group-format Ar GFMT
107 .Op Fl -ignore-all-space
109 .Op Fl -ignore-space-change
112 .Op Fl -no-ignore-file-name-case
116 .Op Fl -show-c-function
117 .Op Fl -speed-large-files
118 .Op Fl -starting-file
119 .Op Fl -strip-trailing-cr
120 .Op Fl -tabsize Ar number
122 .Fl D Ar string | Fl -ifdef Ar string
126 .Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern
127 .Op Fl F Ar pattern | Fl -show-function-line Ar pattern
128 .Op Fl L Ar label | Fl -label Ar label
130 .Op Fl -color Ns = Ns Ar when
131 .Op Fl -changed-group-format Ar GFMT
135 .Op Fl -ignore-all-space
137 .Op Fl -ignore-space-change
140 .Op Fl -no-ignore-file-name-case
144 .Op Fl -show-c-function
145 .Op Fl -speed-large-files
146 .Op Fl -starting-file
147 .Op Fl -strip-trailing-cr
148 .Op Fl -tabsize Ar number
150 .Fl U Ar number | Fl -unified Ar number
153 .Op Fl aBbdilNPprsTtw
159 .Op Fl -color Ns = Ns Ar when
160 .Op Fl -changed-group-format Ar GFMT
165 .Op Fl -ignore-all-space
167 .Op Fl -ignore-space-change
171 .Op Fl -no-ignore-file-name-case
176 .Op Fl -report-identical-files
177 .Op Fl -show-c-function
178 .Op Fl -speed-large-files
179 .Op Fl -strip-trailing-cr
180 .Op Fl -tabsize Ar number
182 .Op Fl -unidirectional-new-file
184 .Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern
185 .Op Fl F Ar pattern | Fl -show-function-line Ar pattern
187 .Op Fl L Ar label | Fl -label Ar label
188 .Op Fl S Ar name | Fl -starting-file Ar name
189 .Op Fl X Ar file | Fl -exclude-from Ar file
190 .Op Fl x Ar pattern | Fl -exclude Ar pattern
195 .Op Fl -color Ns = Ns Ar when
197 .Op Fl -ignore-all-blanks
198 .Op Fl -ignore-blank-lines
201 .Op Fl -no-ignore-file-name-case
202 .Op Fl -strip-trailing-cr
203 .Op Fl -suppress-common-lines
204 .Op Fl -tabsize Ar number
207 .Fl y | Fl -side-by-side
215 utility compares the contents of
219 and writes to the standard output the list of changes necessary to
220 convert one file into the other.
221 No output is produced if the files are identical.
223 Output options (mutually exclusive):
225 .It Fl C Ar number Fl -context Ar number
228 but produces a diff with
232 Produces a diff with 3 lines of context.
235 the output format is modified slightly:
236 the output begins with identification of the files involved and
237 their creation dates and then each change is separated
238 by a line with fifteen
240 The lines removed from
248 Lines which are changed from one file to the other are marked in
251 Changes which lie within 3 lines of each other are grouped together on
253 .It Fl D Ar string Fl -ifdef Ar string
254 Creates a merged version of
258 on the standard output, with C preprocessor controls included so that
259 a compilation of the result without defining
261 is equivalent to compiling
268 Produces output in a form suitable as input for the editor utility,
270 which can then be used to convert file1 into file2.
272 Extra commands are added to the output when comparing directories with
274 so that the result is a
276 script for converting text files which are common to the two directories
282 Identical output to that of the
284 flag, but in reverse order.
285 It cannot be digested by
288 This option prints a summary to stdout and exits with status 0.
290 Produces a script similar to that of
292 but in the opposite order and with a count of changed lines on each
293 insert or delete command.
294 This is the form used by rcsdiff.
296 Just print a line when the files differ.
297 Does not output a list of changes.
298 .It Fl U Ar number Fl -unified Ar number
301 but produces a diff with
307 diff with 3 lines of context.
308 A unified diff is similar to the context diff produced by the
313 all lines to be changed (added and/or removed) are present in
316 This option prints a version string to stdout and exits with status 0.
317 .It Fl y Fl -side-by-side
318 Output in two columns with a marker between them.
319 The marker can be one
322 .Bl -tag -width Ds -offset indent -compact
324 Corresponding lines are identical.
326 Corresponding lines are different.
328 Files differ and only the first file contains the line.
330 Files differ and only the second file contains the line.
337 Treat all files as ASCII text.
341 .Dq Binary files ... differ
342 if files contain binary characters.
343 Use of this option forces
346 .It Fl B Fl -ignore-blank-lines
347 Causes chunks that include only blank lines to be ignored.
348 .It Fl b -ignore-space-change
349 Causes trailing blanks (spaces and tabs) to be ignored, and other
350 strings of blanks to compare equal.
351 .It Fl -color= Ns Oo Ar when Oc
352 Color the additions green, and removals red, or the value in the
354 environment variable.
355 The possible values of
363 will use color if the output is a tty and the
365 environment variable is set to a non-empty string.
367 Try very hard to produce a diff as small as possible.
368 This may consume a lot of processing power and memory when processing
369 large files with many changes.
370 .It Fl F Ar pattern, Fl -show-function-line Ar pattern
373 but display the last line that matches provided pattern.
374 .It Fl I Ar pattern Fl -ignore-matching-lines Ar pattern
375 Ignores changes, insertions, and deletions whose lines match the
376 extended regular expression
380 patterns may be specified.
381 All lines in the change must match some pattern for the change to be
385 for more information on regular expression patterns.
386 .It Fl i -ignore-case
387 Ignores the case of letters.
390 will compare equal to
393 Pass the output through
396 .It Fl L Ar label Fl -label Ar label
399 instead of the first (and second, if this option is specified twice)
400 file name and time in the context or unified diff header.
401 .It Fl p -show-c-function
402 With unified and context diffs, show with each change
403 the first 40 characters of the last line before the context beginning
404 with a letter, an underscore or a dollar sign.
405 For C and Objective-C source code following standard layout conventions, this
406 will show the prototype of the function the change applies to.
407 .It Fl T -initial-tab
408 Print a tab rather than a space before the rest of the line for the
409 normal, context or unified output formats.
410 This makes the alignment of tabs in the line consistent.
411 .It Fl t -expand-tabs
412 Will expand tabs in output lines.
415 output adds character(s) to the front of each line which may screw up
416 the indentation of the original source lines and make the output listing
417 difficult to interpret.
418 This option will preserve the original source's indentation.
419 .It Fl w -ignore-all-blanks
421 .Fl b -ignore-space-change
422 but causes whitespace (blanks and tabs) to be totally ignored.
424 .Dq if (\ \&a == b \&)
425 will compare equal to
427 .It Fl W Ar number Fl -width Ar number
430 columns when using side by side format.
431 The default value is 130.
432 .It Fl -changed-group-format Ar GFMT
433 Format input groups in the provided
435 the format is a string with special keywords:
442 .It Fl -ignore-file-name-case
443 ignore case when comparing file names
444 .It Fl -no-ignore-file-name-case
445 do not ignore case wen comparing file names (default)
448 .It Fl -speed-large-files
449 stub option for compatibility with GNU diff
450 .It Fl -strip-trailing-cr
451 strip carriage return on input files
452 .It Fl -suppress-common-lines
453 Do not output common lines when using the side by side format
454 .It Fl -tabsize Ar number
455 Number of spaces representing a tab (default 8)
458 Directory comparison options:
461 If a file is found in only one directory, act as if it was found in the
462 other directory too but was of zero size.
463 .It Fl P -unidirectional-new-file
464 If a file is found only in
466 act as if it was found in
468 too but was of zero size.
470 Causes application of
472 recursively to common subdirectories encountered.
473 .It Fl S Ar name Fl -starting-file Ar name
474 Re-starts a directory
476 in the middle, beginning with file
478 .It Fl s -report-identical-files
481 to report files which are the same, which are otherwise not mentioned.
482 .It Fl X Ar file Fl -exclude-from Ar file
483 Exclude files and subdirectories from comparison whose basenames match
488 options may be specified.
489 .It Fl x Ar pattern Fl -exclude Ar pattern
490 Exclude files and subdirectories from comparison whose basenames match
492 Patterns are matched using shell-style globbing via
496 options may be specified.
499 If both arguments are directories,
501 sorts the contents of the directories by name, and then runs the
504 algorithm, producing a change list,
505 on text files which are different.
506 Binary files which differ,
507 common subdirectories, and files which appear in only one directory
508 are described as such.
509 In directory mode only regular files and directories are compared.
510 If a non-regular file such as a device special file or FIFO is encountered,
511 a diagnostic message is printed.
519 is applied to the non-directory file and the file contained in
520 the directory file with a filename that is the same as the
521 last component of the non-directory file.
529 the standard input is
539 output contains lines of these forms, where
540 .Va XX , YY , ZZ , QQ
541 are line numbers respective of file order.
543 .Bl -tag -width "XX,YYcZZ,QQ" -compact
544 .It Li XX Ns Ic a Ns Li YY
555 .It Li XX Ns Ic a Ns Li YY,ZZ
556 Same as above, but append the range of lines,
565 .It Li XX Ns Ic d Ns Li YY
572 tells to which line the change would bring
576 .It Li XX,YY Ns Ic d Ns Li ZZ
577 Delete the range of lines
583 .It Li XX Ns Ic c Ns Li YY
592 .It Li XX,YY Ns Ic c Ns Li ZZ
593 Replace the range of specified lines with the line
595 .It Li XX,YY Ns Ic c Ns Li ZZ,QQ
608 subcommands to convert
612 The line numbers before the action letters pertain to
614 those after pertain to
620 and reading the line in reverse order, one can also
621 determine how to convert
628 pairs (where num1 = num2) are abbreviated as a single
631 .Bl -tag -width DIFFCOLORS
633 The value of this variable is the form
634 .Ar add Ns : Ns Ar rm ,
637 is the ASCII escape sequence for additions and
639 is the ASCII escape sequence for deletions.
642 uses green for additions and red for removals.
645 .Bl -tag -width /tmp/diff.XXXXXXXX -compact
646 .It Pa /tmp/diff.XXXXXXXX
647 Temporary file used when comparing a device or the standard input.
648 Note that the temporary file is unlinked as soon as it is created
649 so it will not show up in a directory listing.
654 utility exits with one of the following values:
656 .Bl -tag -width Ds -offset indent -compact
658 No differences were found.
660 Differences were found.
669 options exit with a status of 0.
675 recursively generating an unified diff and treating files found only in one
676 of those directories as new files:
677 .Bd -literal -offset indent
678 $ diff -ruN /path/to/old_dir /path/to/new_dir
681 Same as above but excluding files matching the expressions
685 .Bd -literal -offset indent
686 $ diff -ruN -x '*.h' -x '*.c' /path/to/old_dir /path/to/new_dir
689 Show a single line indicating if the files differ:
690 .Bd -literal -offset indent
691 $ diff -q /boot/loader.conf /boot/defaults/loader.conf
692 Files /boot/loader.conf and /boot/defaults/loader.conf differ
695 Assuming a file named
697 with the following contents:
698 .Bd -literal -offset indent
699 FreeBSD is an operating system
701 OpenBSD is an operating system
706 excluding from the comparison those lines containing either
710 .Bd -literal -offset indent
711 $ echo "FreeBSD is an operating system" | diff -q -I 'Linux|Open' example.txt -
723 .%A M. Douglas McIlroy
724 .%T "An Algorithm for Differential File Comparison"
725 .%J Computing Science Technical Report
726 .%Q Bell Laboratories 41
732 utility is compliant with the
737 .Op Fl aDdIiLlNnPpqSsTtwXxy
738 are extensions to that specification.