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
35 .Nd differential file and directory comparator
44 .Op Fl -color Ns = Ns Ar when
45 .Op Fl -changed-group-format Ar GFMT
49 .Op Fl -ignore-all-space
51 .Op Fl -ignore-space-change
54 .Op Fl -no-ignore-file-name-case
57 .Op Fl -show-c-function
59 .Op Fl -speed-large-files
60 .Op Fl -strip-trailing-cr
61 .Op Fl -tabsize Ar number
64 .Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern
65 .Op Fl F Ar pattern | Fl -show-function-line 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 F Ar pattern | Fl -show-function-line Ar pattern
72 .Op Fl L Ar label | Fl -label Ar label
74 .Op Fl -color Ns = Ns Ar when
75 .Op Fl -changed-group-format Ar GFMT
79 .Op Fl -ignore-all-space
81 .Op Fl -ignore-space-change
84 .Op Fl -no-ignore-file-name-case
88 .Op Fl -show-c-function
89 .Op Fl -speed-large-files
91 .Op Fl -strip-trailing-cr
92 .Op Fl -tabsize Ar number
94 .Fl C Ar number | -context Ar number
98 .Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern
100 .Op Fl -color Ns = Ns Ar when
101 .Op Fl -changed-group-format Ar GFMT
105 .Op Fl -ignore-all-space
107 .Op Fl -ignore-space-change
110 .Op Fl -no-ignore-file-name-case
114 .Op Fl -show-c-function
115 .Op Fl -speed-large-files
116 .Op Fl -starting-file
117 .Op Fl -strip-trailing-cr
118 .Op Fl -tabsize Ar number
120 .Fl D Ar string | Fl -ifdef Ar string
124 .Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern
125 .Op Fl F Ar pattern | Fl -show-function-line Ar pattern
126 .Op Fl L Ar label | Fl -label Ar label
128 .Op Fl -color Ns = Ns Ar when
129 .Op Fl -changed-group-format Ar GFMT
133 .Op Fl -ignore-all-space
135 .Op Fl -ignore-space-change
138 .Op Fl -no-ignore-file-name-case
142 .Op Fl -show-c-function
143 .Op Fl -speed-large-files
144 .Op Fl -starting-file
145 .Op Fl -strip-trailing-cr
146 .Op Fl -tabsize Ar number
148 .Fl U Ar number | Fl -unified Ar number
151 .Op Fl aBbdilNPprsTtw
157 .Op Fl -color Ns = Ns Ar when
158 .Op Fl -changed-group-format Ar GFMT
163 .Op Fl -ignore-all-space
165 .Op Fl -ignore-space-change
169 .Op Fl -no-ignore-file-name-case
174 .Op Fl -report-identical-files
175 .Op Fl -show-c-function
176 .Op Fl -speed-large-files
177 .Op Fl -strip-trailing-cr
178 .Op Fl -tabsize Ar number
180 .Op Fl -unidirectional-new-file
182 .Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern
183 .Op Fl F Ar pattern | Fl -show-function-line Ar pattern
185 .Op Fl L Ar label | Fl -label Ar label
186 .Op Fl S Ar name | Fl -starting-file Ar name
187 .Op Fl X Ar file | Fl -exclude-from Ar file
188 .Op Fl x Ar pattern | Fl -exclude Ar pattern
193 .Op Fl -color Ns = Ns Ar when
195 .Op Fl -ignore-all-blanks
196 .Op Fl -ignore-blank-lines
199 .Op Fl -no-ignore-file-name-case
200 .Op Fl -strip-trailing-cr
201 .Op Fl -suppress-common-lines
202 .Op Fl -tabsize Ar number
205 .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 This option prints a summary to stdout and exits with status 0.
288 Produces a script similar to that of
290 but in the opposite order and with a count of changed lines on each
291 insert or delete command.
292 This is the form used by rcsdiff.
294 Just print a line when the files differ.
295 Does not output a list of changes.
296 .It Fl U Ar number Fl -unified Ar number
299 but produces a diff with
305 diff with 3 lines of context.
306 A unified diff is similar to the context diff produced by the
311 all lines to be changed (added and/or removed) are present in
314 This option prints a version string to stdout and exits with status 0.
315 .It Fl y Fl -side-by-side
316 Output in two columns with a marker between them.
317 The marker can be one
320 .Bl -tag -width Ds -offset indent -compact
322 Corresponding lines are identical.
324 Corresponding lines are different.
326 Files differ and only the first file contains the line.
328 Files differ and only the second file contains the line.
335 Treat all files as ASCII text.
339 .Dq Binary files ... differ
340 if files contain binary characters.
341 Use of this option forces
344 .It Fl B Fl -ignore-blank-lines
345 Causes chunks that include only blank lines to be ignored.
346 .It Fl b -ignore-space-change
347 Causes trailing blanks (spaces and tabs) to be ignored, and other
348 strings of blanks to compare equal.
349 .It Fl -color= Ns Oo Ar when Oc
350 Color the additions green, and removals red, or the value in the
352 environment variable.
353 The possible values of
361 will use color if the output is a tty and the
363 environment variable is set to a non-empty string.
365 Try very hard to produce a diff as small as possible.
366 This may consume a lot of processing power and memory when processing
367 large files with many changes.
368 .It Fl F Ar pattern, Fl -show-function-line Ar pattern
371 but display the last line that matches provided pattern.
372 .It Fl I Ar pattern Fl -ignore-matching-lines Ar pattern
373 Ignores changes, insertions, and deletions whose lines match the
374 extended regular expression
378 patterns may be specified.
379 All lines in the change must match some pattern for the change to be
383 for more information on regular expression patterns.
384 .It Fl i -ignore-case
385 Ignores the case of letters.
388 will compare equal to
391 Pass the output through
394 .It Fl L Ar label Fl -label Ar label
397 instead of the first (and second, if this option is specified twice)
398 file name and time in the context or unified diff header.
399 .It Fl p -show-c-function
400 With unified and context diffs, show with each change
401 the first 40 characters of the last line before the context beginning
402 with a letter, an underscore or a dollar sign.
403 For C and Objective-C source code following standard layout conventions, this
404 will show the prototype of the function the change applies to.
405 .It Fl T -initial-tab
406 Print a tab rather than a space before the rest of the line for the
407 normal, context or unified output formats.
408 This makes the alignment of tabs in the line consistent.
409 .It Fl t -expand-tabs
410 Will expand tabs in output lines.
413 output adds character(s) to the front of each line which may screw up
414 the indentation of the original source lines and make the output listing
415 difficult to interpret.
416 This option will preserve the original source's indentation.
417 .It Fl w -ignore-all-blanks
419 .Fl b -ignore-space-change
420 but causes whitespace (blanks and tabs) to be totally ignored.
422 .Dq if (\ \&a == b \&)
423 will compare equal to
425 .It Fl W Ar number Fl -width Ar number
428 columns when using side by side format.
429 The default value is 130.
430 .It Fl -changed-group-format Ar GFMT
431 Format input groups in the provided
433 the format is a string with special keywords:
440 .It Fl -ignore-file-name-case
441 ignore case when comparing file names
442 .It Fl -no-ignore-file-name-case
443 do not ignore case wen comparing file names (default)
446 .It Fl -speed-large-files
447 stub option for compatibility with GNU diff
448 .It Fl -strip-trailing-cr
449 strip carriage return on input files
450 .It Fl -suppress-common-lines
451 Do not output common lines when using the side by side format
452 .It Fl -tabsize Ar number
453 Number of spaces representing a tab (default 8)
456 Directory comparison options:
459 If a file is found in only one directory, act as if it was found in the
460 other directory too but was of zero size.
461 .It Fl P -unidirectional-new-file
462 If a file is found only in
464 act as if it was found in
466 too but was of zero size.
468 Causes application of
470 recursively to common subdirectories encountered.
471 .It Fl S Ar name Fl -starting-file Ar name
472 Re-starts a directory
474 in the middle, beginning with file
476 .It Fl s -report-identical-files
479 to report files which are the same, which are otherwise not mentioned.
480 .It Fl X Ar file Fl -exclude-from Ar file
481 Exclude files and subdirectories from comparison whose basenames match
486 options may be specified.
487 .It Fl x Ar pattern Fl -exclude Ar pattern
488 Exclude files and subdirectories from comparison whose basenames match
490 Patterns are matched using shell-style globbing via
494 options may be specified.
497 If both arguments are directories,
499 sorts the contents of the directories by name, and then runs the
502 algorithm, producing a change list,
503 on text files which are different.
504 Binary files which differ,
505 common subdirectories, and files which appear in only one directory
506 are described as such.
507 In directory mode only regular files and directories are compared.
508 If a non-regular file such as a device special file or FIFO is encountered,
509 a diagnostic message is printed.
517 is applied to the non-directory file and the file contained in
518 the directory file with a filename that is the same as the
519 last component of the non-directory file.
527 the standard input is
537 output contains lines of these forms, where
538 .Va XX , YY , ZZ , QQ
539 are line numbers respective of file order.
541 .Bl -tag -width "XX,YYcZZ,QQ" -compact
542 .It Li XX Ns Ic a Ns Li YY
553 .It Li XX Ns Ic a Ns Li YY,ZZ
554 Same as above, but append the range of lines,
563 .It Li XX Ns Ic d Ns Li YY
570 tells to which line the change would bring
574 .It Li XX,YY Ns Ic d Ns Li ZZ
575 Delete the range of lines
581 .It Li XX Ns Ic c Ns Li YY
590 .It Li XX,YY Ns Ic c Ns Li ZZ
591 Replace the range of specified lines with the line
593 .It Li XX,YY Ns Ic c Ns Li ZZ,QQ
606 subcommands to convert
610 The line numbers before the action letters pertain to
612 those after pertain to
618 and reading the line in reverse order, one can also
619 determine how to convert
626 pairs (where num1 = num2) are abbreviated as a single
629 .Bl -tag -width DIFFCOLORS
631 The value of this variable is the form
632 .Ar add Ns : Ns Ar rm ,
635 is the ASCII escape sequence for additions and
637 is the ASCII escape sequence for deletions.
640 uses green for additions and red for removals.
643 .Bl -tag -width /tmp/diff.XXXXXXXX -compact
644 .It Pa /tmp/diff.XXXXXXXX
645 Temporary file used when comparing a device or the standard input.
646 Note that the temporary file is unlinked as soon as it is created
647 so it will not show up in a directory listing.
652 utility exits with one of the following values:
654 .Bl -tag -width Ds -offset indent -compact
656 No differences were found.
658 Differences were found.
667 options exit with a status of 0.
673 recursively generating an unified diff and treating files found only in one
674 of those directories as new files:
675 .Bd -literal -offset indent
676 $ diff -ruN /path/to/old_dir /path/to/new_dir
679 Same as above but excluding files matching the expressions
683 .Bd -literal -offset indent
684 $ diff -ruN -x '*.h' -x '*.c' /path/to/old_dir /path/to/new_dir
687 Show a single line indicating if the files differ:
688 .Bd -literal -offset indent
689 $ diff -q /boot/loader.conf /boot/defaults/loader.conf
690 Files /boot/loader.conf and /boot/defaults/loader.conf differ
693 Assuming a file named
695 with the following contents:
696 .Bd -literal -offset indent
697 FreeBSD is an operating system
699 OpenBSD is an operating system
704 excluding from the comparison those lines containing either
708 .Bd -literal -offset indent
709 $ echo "FreeBSD is an operating system" | diff -q -I 'Linux|Open' example.txt -
721 .%A M. Douglas McIlroy
722 .%T "An Algorithm for Differential File Comparison"
723 .%J Computing Science Technical Report
724 .%Q Bell Laboratories 41
730 utility is compliant with the
735 .Op Fl aDdIiLlNnPpqSsTtwXxy
736 are extensions to that specification.