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
216 utility compares the contents of
220 and writes to the standard output the list of changes necessary to
221 convert one file into the other.
222 No output is produced if the files are identical.
224 Output options (mutually exclusive):
226 .It Fl C Ar number Fl -context Ar number
229 but produces a diff with
233 Produces a diff with 3 lines of context.
236 the output format is modified slightly:
237 the output begins with identification of the files involved and
238 their creation dates and then each change is separated
239 by a line with fifteen
241 The lines removed from
249 Lines which are changed from one file to the other are marked in
252 Changes which lie within 3 lines of each other are grouped together on
254 .It Fl D Ar string Fl -ifdef Ar string
255 Creates a merged version of
259 on the standard output, with C preprocessor controls included so that
260 a compilation of the result without defining
262 is equivalent to compiling
269 Produces output in a form suitable as input for the editor utility,
271 which can then be used to convert file1 into file2.
273 Extra commands are added to the output when comparing directories with
275 so that the result is a
277 script for converting text files which are common to the two directories
283 Identical output to that of the
285 flag, but in reverse order.
286 It cannot be digested by
289 This option prints a summary to stdout and exits with status 0.
291 Produces a script similar to that of
293 but in the opposite order and with a count of changed lines on each
294 insert or delete command.
295 This is the form used by rcsdiff.
297 Just print a line when the files differ.
298 Does not output a list of changes.
299 .It Fl U Ar number Fl -unified Ar number
302 but produces a diff with
308 diff with 3 lines of context.
309 A unified diff is similar to the context diff produced by the
314 all lines to be changed (added and/or removed) are present in
317 This option prints a version string to stdout and exits with status 0.
318 .It Fl y Fl -side-by-side
319 Output in two columns with a marker between them.
320 The marker can be one
323 .Bl -tag -width Ds -offset indent -compact
325 Corresponding lines are identical.
327 Corresponding lines are different.
329 Files differ and only the first file contains the line.
331 Files differ and only the second file contains the line.
338 Treat all files as ASCII text.
342 .Dq Binary files ... differ
343 if files contain binary characters.
344 Use of this option forces
347 .It Fl B Fl -ignore-blank-lines
348 Causes chunks that include only blank lines to be ignored.
349 .It Fl b -ignore-space-change
350 Causes trailing blanks (spaces and tabs) to be ignored, and other
351 strings of blanks to compare equal.
352 .It Fl -color= Ns Oo Ar when Oc
353 Color the additions green, and removals red, or the value in the
355 environment variable.
356 The possible values of
364 will use color if the output is a tty and the
366 environment variable is set to a non-empty string.
368 Try very hard to produce a diff as small as possible.
369 This may consume a lot of processing power and memory when processing
370 large files with many changes.
371 .It Fl F Ar pattern, Fl -show-function-line Ar pattern
374 but display the last line that matches provided pattern.
375 .It Fl I Ar pattern Fl -ignore-matching-lines Ar pattern
376 Ignores changes, insertions, and deletions whose lines match the
377 extended regular expression
381 patterns may be specified.
382 All lines in the change must match some pattern for the change to be
386 for more information on regular expression patterns.
387 .It Fl i -ignore-case
388 Ignores the case of letters.
391 will compare equal to
394 Pass the output through
397 .It Fl L Ar label Fl -label Ar label
400 instead of the first (and second, if this option is specified twice)
401 file name and time in the context or unified diff header.
402 .It Fl p -show-c-function
403 With unified and context diffs, show with each change
404 the first 40 characters of the last line before the context beginning
405 with a letter, an underscore or a dollar sign.
406 For C and Objective-C source code following standard layout conventions, this
407 will show the prototype of the function the change applies to.
408 .It Fl T -initial-tab
409 Print a tab rather than a space before the rest of the line for the
410 normal, context or unified output formats.
411 This makes the alignment of tabs in the line consistent.
412 .It Fl t -expand-tabs
413 Will expand tabs in output lines.
416 output adds character(s) to the front of each line which may screw up
417 the indentation of the original source lines and make the output listing
418 difficult to interpret.
419 This option will preserve the original source's indentation.
420 .It Fl w -ignore-all-blanks
422 .Fl b -ignore-space-change
423 but causes whitespace (blanks and tabs) to be totally ignored.
425 .Dq if (\ \&a == b \&)
426 will compare equal to
428 .It Fl W Ar number Fl -width Ar number
431 columns when using side by side format.
432 The default value is 130.
433 .It Fl -changed-group-format Ar GFMT
434 Format input groups in the provided
436 the format is a string with special keywords:
443 .It Fl -ignore-file-name-case
444 ignore case when comparing file names
445 .It Fl -no-ignore-file-name-case
446 do not ignore case wen comparing file names (default)
449 .It Fl -speed-large-files
450 stub option for compatibility with GNU diff
451 .It Fl -strip-trailing-cr
452 strip carriage return on input files
453 .It Fl -suppress-common-lines
454 Do not output common lines when using the side by side format
455 .It Fl -tabsize Ar number
456 Number of spaces representing a tab (default 8)
459 Directory comparison options:
462 If a file is found in only one directory, act as if it was found in the
463 other directory too but was of zero size.
464 .It Fl P -unidirectional-new-file
465 If a file is found only in
467 act as if it was found in
469 too but was of zero size.
471 Causes application of
473 recursively to common subdirectories encountered.
474 .It Fl S Ar name Fl -starting-file Ar name
475 Re-starts a directory
477 in the middle, beginning with file
479 .It Fl s -report-identical-files
482 to report files which are the same, which are otherwise not mentioned.
483 .It Fl X Ar file Fl -exclude-from Ar file
484 Exclude files and subdirectories from comparison whose basenames match
489 options may be specified.
490 .It Fl x Ar pattern Fl -exclude Ar pattern
491 Exclude files and subdirectories from comparison whose basenames match
493 Patterns are matched using shell-style globbing via
497 options may be specified.
500 If both arguments are directories,
502 sorts the contents of the directories by name, and then runs the
505 algorithm, producing a change list,
506 on text files which are different.
507 Binary files which differ,
508 common subdirectories, and files which appear in only one directory
509 are described as such.
510 In directory mode only regular files and directories are compared.
511 If a non-regular file such as a device special file or FIFO is encountered,
512 a diagnostic message is printed.
520 is applied to the non-directory file and the file contained in
521 the directory file with a filename that is the same as the
522 last component of the non-directory file.
530 the standard input is
540 output contains lines of these forms, where
541 .Va XX , YY , ZZ , QQ
542 are line numbers respective of file order.
544 .Bl -tag -width "XX,YYcZZ,QQ" -compact
545 .It Li XX Ns Ic a Ns Li YY
556 .It Li XX Ns Ic a Ns Li YY,ZZ
557 Same as above, but append the range of lines,
566 .It Li XX Ns Ic d Ns Li YY
573 tells to which line the change would bring
577 .It Li XX,YY Ns Ic d Ns Li ZZ
578 Delete the range of lines
584 .It Li XX Ns Ic c Ns Li YY
593 .It Li XX,YY Ns Ic c Ns Li ZZ
594 Replace the range of specified lines with the line
596 .It Li XX,YY Ns Ic c Ns Li ZZ,QQ
609 subcommands to convert
613 The line numbers before the action letters pertain to
615 those after pertain to
621 and reading the line in reverse order, one can also
622 determine how to convert
629 pairs (where num1 = num2) are abbreviated as a single
632 .Bl -tag -width DIFFCOLORS
634 The value of this variable is the form
635 .Ar add Ns : Ns Ar rm ,
638 is the ASCII escape sequence for additions and
640 is the ASCII escape sequence for deletions.
643 uses green for additions and red for removals.
646 .Bl -tag -width /tmp/diff.XXXXXXXX -compact
647 .It Pa /tmp/diff.XXXXXXXX
648 Temporary file used when comparing a device or the standard input.
649 Note that the temporary file is unlinked as soon as it is created
650 so it will not show up in a directory listing.
655 utility exits with one of the following values:
657 .Bl -tag -width Ds -offset indent -compact
659 No differences were found.
661 Differences were found.
670 options exit with a status of 0.
676 recursively generating an unified diff and treating files found only in one
677 of those directories as new files:
678 .Bd -literal -offset indent
679 $ diff -ruN /path/to/old_dir /path/to/new_dir
682 Same as above but excluding files matching the expressions
686 .Bd -literal -offset indent
687 $ diff -ruN -x '*.h' -x '*.c' /path/to/old_dir /path/to/new_dir
690 Show a single line indicating if the files differ:
691 .Bd -literal -offset indent
692 $ diff -q /boot/loader.conf /boot/defaults/loader.conf
693 Files /boot/loader.conf and /boot/defaults/loader.conf differ
696 Assuming a file named
698 with the following contents:
699 .Bd -literal -offset indent
700 FreeBSD is an operating system
702 OpenBSD is an operating system
707 excluding from the comparison those lines containing either
711 .Bd -literal -offset indent
712 $ echo "FreeBSD is an operating system" | diff -q -I 'Linux|Open' example.txt -
724 .%A M. Douglas McIlroy
725 .%T "An Algorithm for Differential File Comparison"
726 .%J Computing Science Technical Report
727 .%Q Bell Laboratories 41
733 utility is compliant with the
738 .Op Fl aDdIiLlNnPpqSsTtwXxy
739 are extensions to that specification.