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 -color Ns = Ns Ar when
48 .Op Fl -changed-group-format Ar GFMT
52 .Op Fl -ignore-all-space
54 .Op Fl -ignore-space-change
57 .Op Fl -no-ignore-file-name-case
60 .Op Fl -show-c-function
62 .Op Fl -speed-large-files
63 .Op Fl -strip-trailing-cr
64 .Op Fl -tabsize Ar number
67 .Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern
68 .Op Fl F Ar pattern | Fl -show-function-line Ar pattern
69 .Op Fl L Ar label | Fl -label Ar label
73 .Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern
74 .Op Fl F Ar pattern | Fl -show-function-line Ar pattern
75 .Op Fl L Ar label | Fl -label Ar label
77 .Op Fl -color Ns = Ns Ar when
78 .Op Fl -changed-group-format Ar GFMT
82 .Op Fl -ignore-all-space
84 .Op Fl -ignore-space-change
87 .Op Fl -no-ignore-file-name-case
91 .Op Fl -show-c-function
92 .Op Fl -speed-large-files
94 .Op Fl -strip-trailing-cr
95 .Op Fl -tabsize Ar number
97 .Fl C Ar number | -context Ar number
101 .Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern
103 .Op Fl -color Ns = Ns Ar when
104 .Op Fl -changed-group-format Ar GFMT
108 .Op Fl -ignore-all-space
110 .Op Fl -ignore-space-change
113 .Op Fl -no-ignore-file-name-case
117 .Op Fl -show-c-function
118 .Op Fl -speed-large-files
119 .Op Fl -starting-file
120 .Op Fl -strip-trailing-cr
121 .Op Fl -tabsize Ar number
123 .Fl D Ar string | Fl -ifdef Ar string
127 .Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern
128 .Op Fl F Ar pattern | Fl -show-function-line Ar pattern
129 .Op Fl L Ar label | Fl -label Ar label
131 .Op Fl -color Ns = Ns Ar when
132 .Op Fl -changed-group-format Ar GFMT
136 .Op Fl -ignore-all-space
138 .Op Fl -ignore-space-change
141 .Op Fl -no-ignore-file-name-case
145 .Op Fl -show-c-function
146 .Op Fl -speed-large-files
147 .Op Fl -starting-file
148 .Op Fl -strip-trailing-cr
149 .Op Fl -tabsize Ar number
151 .Fl U Ar number | Fl -unified Ar number
154 .Op Fl aBbdilNPprsTtw
160 .Op Fl -color Ns = Ns Ar when
161 .Op Fl -changed-group-format Ar GFMT
166 .Op Fl -ignore-all-space
168 .Op Fl -ignore-space-change
172 .Op Fl -no-ignore-file-name-case
177 .Op Fl -report-identical-files
178 .Op Fl -show-c-function
179 .Op Fl -speed-large-files
180 .Op Fl -strip-trailing-cr
181 .Op Fl -tabsize Ar number
183 .Op Fl -unidirectional-new-file
185 .Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern
186 .Op Fl F Ar pattern | Fl -show-function-line Ar pattern
188 .Op Fl L Ar label | Fl -label Ar label
189 .Op Fl S Ar name | Fl -starting-file Ar name
190 .Op Fl X Ar file | Fl -exclude-from Ar file
191 .Op Fl x Ar pattern | Fl -exclude Ar pattern
196 .Op Fl -color Ns = Ns Ar when
198 .Op Fl -ignore-all-blanks
199 .Op Fl -ignore-blank-lines
202 .Op Fl -no-ignore-file-name-case
203 .Op Fl -strip-trailing-cr
204 .Op Fl -suppress-common-lines
205 .Op Fl -tabsize Ar number
208 .Fl y | Fl -side-by-side
213 utility compares the contents of
217 and writes to the standard output the list of changes necessary to
218 convert one file into the other.
219 No output is produced if the files are identical.
221 Output options (mutually exclusive):
223 .It Fl C Ar number Fl -context Ar number
226 but produces a diff with
230 Produces a diff with 3 lines of context.
233 the output format is modified slightly:
234 the output begins with identification of the files involved and
235 their creation dates and then each change is separated
236 by a line with fifteen
238 The lines removed from
246 Lines which are changed from one file to the other are marked in
249 Changes which lie within 3 lines of each other are grouped together on
251 .It Fl D Ar string Fl -ifdef Ar string
252 Creates a merged version of
256 on the standard output, with C preprocessor controls included so that
257 a compilation of the result without defining
259 is equivalent to compiling
266 Produces output in a form suitable as input for the editor utility,
268 which can then be used to convert file1 into file2.
270 Extra commands are added to the output when comparing directories with
272 so that the result is a
274 script for converting text files which are common to the two directories
280 Identical output to that of the
282 flag, but in reverse order.
283 It cannot be digested by
286 Produces a script similar to that of
288 but in the opposite order and with a count of changed lines on each
289 insert or delete command.
290 This is the form used by rcsdiff.
292 Just print a line when the files differ.
293 Does not output a list of changes.
294 .It Fl U Ar number Fl -unified Ar number
297 but produces a diff with
303 diff with 3 lines of context.
304 A unified diff is similar to the context diff produced by the
309 all lines to be changed (added and/or removed) are present in
311 .It Fl y Fl -side-by-side
312 Output in two columns with a marker between them.
313 The marker can be one
316 .Bl -tag -width Ds -offset indent -compact
318 Corresponding lines are identical.
320 Corresponding lines are different.
322 Files differ and only the first file contains the line.
324 Files differ and only the second file contains the line.
331 Treat all files as ASCII text.
335 .Dq Binary files ... differ
336 if files contain binary characters.
337 Use of this option forces
340 .It Fl B Fl -ignore-blank-lines
341 Causes chunks that include only blank lines to be ignored.
342 .It Fl b -ignore-space-change
343 Causes trailing blanks (spaces and tabs) to be ignored, and other
344 strings of blanks to compare equal.
345 .It Fl -color= Ns Oo Ar when Oc
346 Color the additions green, and removals red, or the value in the
348 environment variable.
349 The possible values of
357 will use color if the output is a tty and the
359 environment variable is set to a non-empty string.
361 Try very hard to produce a diff as small as possible.
362 This may consume a lot of processing power and memory when processing
363 large files with many changes.
364 .It Fl F Ar pattern, Fl -show-function-line Ar pattern
367 but display the last line that matches provided pattern.
368 .It Fl I Ar pattern Fl -ignore-matching-lines Ar pattern
369 Ignores changes, insertions, and deletions whose lines match the
370 extended regular expression
374 patterns may be specified.
375 All lines in the change must match some pattern for the change to be
379 for more information on regular expression patterns.
380 .It Fl i -ignore-case
381 Ignores the case of letters.
384 will compare equal to
387 Pass the output through
390 .It Fl L Ar label Fl -label Ar label
393 instead of the first (and second, if this option is specified twice)
394 file name and time in the context or unified diff header.
395 .It Fl p -show-c-function
396 With unified and context diffs, show with each change
397 the first 40 characters of the last line before the context beginning
398 with a letter, an underscore or a dollar sign.
399 For C and Objective-C source code following standard layout conventions, this
400 will show the prototype of the function the change applies to.
401 .It Fl T -initial-tab
402 Print a tab rather than a space before the rest of the line for the
403 normal, context or unified output formats.
404 This makes the alignment of tabs in the line consistent.
405 .It Fl t -expand-tabs
406 Will expand tabs in output lines.
409 output adds character(s) to the front of each line which may screw up
410 the indentation of the original source lines and make the output listing
411 difficult to interpret.
412 This option will preserve the original source's indentation.
413 .It Fl w -ignore-all-blanks
415 .Fl b -ignore-space-change
416 but causes whitespace (blanks and tabs) to be totally ignored.
418 .Dq if (\ \&a == b \&)
419 will compare equal to
421 .It Fl W Ar number Fl -width Ar number
424 columns when using side by side format.
425 The default value is 130.
426 .It Fl -changed-group-format Ar GFMT
427 Format input groups in the provided
429 the format is a string with special keywords:
436 .It Fl -ignore-file-name-case
437 ignore case when comparing file names
438 .It Fl -no-ignore-file-name-case
439 do not ignore case wen comparing file names (default)
442 .It Fl -speed-large-files
443 stub option for compatibility with GNU diff
444 .It Fl -strip-trailing-cr
445 strip carriage return on input files
446 .It Fl -suppress-common-lines
447 Do not output common lines when using the side by side format
448 .It Fl -tabsize Ar number
449 Number of spaces representing a tab (default 8)
452 Directory comparison options:
455 If a file is found in only one directory, act as if it was found in the
456 other directory too but was of zero size.
457 .It Fl P -unidirectional-new-file
458 If a file is found only in
460 act as if it was found in
462 too but was of zero size.
464 Causes application of
466 recursively to common subdirectories encountered.
467 .It Fl S Ar name Fl -starting-file Ar name
468 Re-starts a directory
470 in the middle, beginning with file
472 .It Fl s -report-identical-files
475 to report files which are the same, which are otherwise not mentioned.
476 .It Fl X Ar file Fl -exclude-from Ar file
477 Exclude files and subdirectories from comparison whose basenames match
482 options may be specified.
483 .It Fl x Ar pattern Fl -exclude Ar pattern
484 Exclude files and subdirectories from comparison whose basenames match
486 Patterns are matched using shell-style globbing via
490 options may be specified.
493 If both arguments are directories,
495 sorts the contents of the directories by name, and then runs the
498 algorithm, producing a change list,
499 on text files which are different.
500 Binary files which differ,
501 common subdirectories, and files which appear in only one directory
502 are described as such.
503 In directory mode only regular files and directories are compared.
504 If a non-regular file such as a device special file or FIFO is encountered,
505 a diagnostic message is printed.
513 is applied to the non-directory file and the file contained in
514 the directory file with a filename that is the same as the
515 last component of the non-directory file.
523 the standard input is
533 output contains lines of these forms, where
534 .Va XX , YY , ZZ , QQ
535 are line numbers respective of file order.
537 .Bl -tag -width "XX,YYcZZ,QQ" -compact
538 .It Li XX Ns Ic a Ns Li YY
549 .It Li XX Ns Ic a Ns Li YY,ZZ
550 Same as above, but append the range of lines,
559 .It Li XX Ns Ic d Ns Li YY
566 tells to which line the change would bring
570 .It Li XX,YY Ns Ic d Ns Li ZZ
571 Delete the range of lines
577 .It Li XX Ns Ic c Ns Li YY
586 .It Li XX,YY Ns Ic c Ns Li ZZ
587 Replace the range of specified lines with the line
589 .It Li XX,YY Ns Ic c Ns Li ZZ,QQ
602 subcommands to convert
606 The line numbers before the action letters pertain to
608 those after pertain to
614 and reading the line in reverse order, one can also
615 determine how to convert
622 pairs (where num1 = num2) are abbreviated as a single
625 .Bl -tag -width DIFFCOLORS
627 The value of this variable is the form
628 .Ar add Ns : Ns Ar rm ,
631 is the ASCII escape sequence for additions and
633 is the ASCII escape sequence for deletions.
636 uses green for additions and red for removals.
639 .Bl -tag -width /tmp/diff.XXXXXXXX -compact
640 .It Pa /tmp/diff.XXXXXXXX
641 Temporary file used when comparing a device or the standard input.
642 Note that the temporary file is unlinked as soon as it is created
643 so it will not show up in a directory listing.
648 utility exits with one of the following values:
650 .Bl -tag -width Ds -offset indent -compact
652 No differences were found.
654 Differences were found.
663 recursively generating an unified diff and treating files found only in one
664 of those directories as new files:
665 .Bd -literal -offset indent
666 $ diff -ruN /path/to/old_dir /path/to/new_dir
669 Same as above but excluding files matching the expressions
673 .Bd -literal -offset indent
674 $ diff -ruN -x '*.h' -x '*.c' /path/to/old_dir /path/to/new_dir
677 Show a single line indicating if the files differ:
678 .Bd -literal -offset indent
679 $ diff -q /boot/loader.conf /boot/defaults/loader.conf
680 Files /boot/loader.conf and /boot/defaults/loader.conf differ
683 Assuming a file named
685 with the following contents:
686 .Bd -literal -offset indent
687 FreeBSD is an operating system
689 OpenBSD is an operating system
694 excluding from the comparison those lines containing either
698 .Bd -literal -offset indent
699 $ echo "FreeBSD is an operating system" | diff -q -I 'Linux|Open' example.txt -
711 .%A M. Douglas McIlroy
712 .%T "An Algorithm for Differential File Comparison"
713 .%J Computing Science Technical Report
714 .%Q Bell Laboratories 41
720 utility is compliant with the
725 .Op Fl aDdIiLlNnPpqSsTtwXxy
726 are extensions to that specification.