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
63 .Op Fl -tabsize Ar number
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
91 .Op Fl -tabsize Ar number
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
116 .Op Fl -tabsize Ar number
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
142 .Op Fl -tabsize Ar number
144 .Fl U Ar number | Fl -unified Ar number
147 .Op Fl aBbdilNPprsTtw
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
173 .Op Fl -tabsize Ar number
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 .Op Fl -ignore-all-blanks
189 .Op Fl -ignore-blank-lines
192 .Op Fl -no-ignore-file-name-case
193 .Op Fl -strip-trailing-cr
194 .Op Fl -suppress-common-lines
195 .Op Fl -tabsize Ar number
198 .Fl y | Fl -side-by-side
203 utility compares the contents of
207 and writes to the standard output the list of changes necessary to
208 convert one file into the other.
209 No output is produced if the files are identical.
211 Output options (mutually exclusive):
213 .It Fl C Ar number Fl -context Ar number
216 but produces a diff with
220 Produces a diff with 3 lines of context.
223 the output format is modified slightly:
224 the output begins with identification of the files involved and
225 their creation dates and then each change is separated
226 by a line with fifteen
228 The lines removed from
236 Lines which are changed from one file to the other are marked in
239 Changes which lie within 3 lines of each other are grouped together on
241 .It Fl D Ar string Fl -ifdef Ar string
242 Creates a merged version of
246 on the standard output, with C preprocessor controls included so that
247 a compilation of the result without defining
249 is equivalent to compiling
256 Produces output in a form suitable as input for the editor utility,
258 which can then be used to convert file1 into file2.
260 Extra commands are added to the output when comparing directories with
262 so that the result is a
264 script for converting text files which are common to the two directories
270 Identical output to that of the
272 flag, but in reverse order.
273 It cannot be digested by
276 Produces a script similar to that of
278 but in the opposite order and with a count of changed lines on each
279 insert or delete command.
280 This is the form used by rcsdiff.
282 Just print a line when the files differ.
283 Does not output a list of changes.
284 .It Fl U Ar number Fl -unified Ar number
287 but produces a diff with
293 diff with 3 lines of context.
294 A unified diff is similar to the context diff produced by the
299 all lines to be changed (added and/or removed) are present in
301 .It Fl y Fl -side-by-side
302 Output in two columns with a marker between them.
303 The marker can be one
306 .Bl -tag -width Ds -offset indent -compact
308 Corresponding lines are identical.
310 Corresponding lines are different.
312 Files differ and only the first file contains the line.
314 Files differ and only the second file contains the line.
321 Treat all files as ASCII text.
325 .Dq Binary files ... differ
326 if files contain binary characters.
327 Use of this option forces
330 .It Fl B Fl -ignore-blank-lines
331 Causes chunks that include only blank lines to be ignored.
332 .It Fl b -ignore-space-change
333 Causes trailing blanks (spaces and tabs) to be ignored, and other
334 strings of blanks to compare equal.
336 Try very hard to produce a diff as small as possible.
337 This may consume a lot of processing power and memory when processing
338 large files with many changes.
339 .It Fl I Ar pattern Fl -ignore-matching-lines Ar pattern
340 Ignores changes, insertions, and deletions whose lines match the
341 extended regular expression
345 patterns may be specified.
346 All lines in the change must match some pattern for the change to be
350 for more information on regular expression patterns.
351 .It Fl i -ignore-case
352 Ignores the case of letters.
355 will compare equal to
358 Pass the output through
361 .It Fl L Ar label Fl -label Ar label
364 instead of the first (and second, if this option is specified twice)
365 file name and time in the context or unified diff header.
366 .It Fl p -show-c-function
367 With unified and context diffs, show with each change
368 the first 40 characters of the last line before the context beginning
369 with a letter, an underscore or a dollar sign.
370 For C source code following standard layout conventions, this will
371 show the prototype of the function the change applies to.
372 .It Fl T -initial-tab
373 Print a tab rather than a space before the rest of the line for the
374 normal, context or unified output formats.
375 This makes the alignment of tabs in the line consistent.
376 .It Fl t -expand-tabs
377 Will expand tabs in output lines.
380 output adds character(s) to the front of each line which may screw up
381 the indentation of the original source lines and make the output listing
382 difficult to interpret.
383 This option will preserve the original source's indentation.
384 .It Fl w -ignore-all-blanks
386 .Fl b -ignore-space-change
387 but causes whitespace (blanks and tabs) to be totally ignored.
389 .Dq if (\ \&a == b \&)
390 will compare equal to
392 .It Fl W Ar number Fl -width Ar number
395 columns when using side by side format.
396 The default value is 130.
397 .It Fl -changed-group-format Ar GFMT
398 Format input groups in the provided
400 the format is a string with special keywords:
407 .It Fl -ignore-file-name-case
408 ignore case when comparing file names
409 .It Fl -no-ignore-file-name-case
410 do not ignore case wen comparing file names (default)
413 .It Fl -speed-large-files
414 stub option for compatibility with GNU diff
415 .It Fl -strip-trailing-cr
416 strip carriage return on input files
417 .It Fl -suppress-common-lines
418 Do not output common lines when using the side by side format
419 .It Fl -tabsize Ar number
420 Number of spaces representing a tab (default 8)
423 Directory comparison options:
426 If a file is found in only one directory, act as if it was found in the
427 other directory too but was of zero size.
428 .It Fl P -unidirectional-new-file
429 If a file is found only in
431 act as if it was found in
433 too but was of zero size.
435 Causes application of
437 recursively to common subdirectories encountered.
438 .It Fl S Ar name Fl -starting-file Ar name
439 Re-starts a directory
441 in the middle, beginning with file
443 .It Fl s -report-identical-files
446 to report files which are the same, which are otherwise not mentioned.
447 .It Fl X Ar file Fl -exclude-from Ar file
448 Exclude files and subdirectories from comparison whose basenames match
453 options may be specified.
454 .It Fl x Ar pattern Fl -exclude Ar pattern
455 Exclude files and subdirectories from comparison whose basenames match
457 Patterns are matched using shell-style globbing via
461 options may be specified.
464 If both arguments are directories,
466 sorts the contents of the directories by name, and then runs the
469 algorithm, producing a change list,
470 on text files which are different.
471 Binary files which differ,
472 common subdirectories, and files which appear in only one directory
473 are described as such.
474 In directory mode only regular files and directories are compared.
475 If a non-regular file such as a device special file or FIFO is encountered,
476 a diagnostic message is printed.
484 is applied to the non-directory file and the file contained in
485 the directory file with a filename that is the same as the
486 last component of the non-directory file.
494 the standard input is
504 output contains lines of these forms, where
505 .Va XX , YY , ZZ , QQ
506 are line numbers respective of file order.
508 .Bl -tag -width "XX,YYcZZ,QQ" -compact
509 .It Li XX Ns Ic a Ns Li YY
520 .It Li XX Ns Ic a Ns Li YY,ZZ
521 Same as above, but append the range of lines,
530 .It Li XX Ns Ic d Ns Li YY
537 tells to which line the change would bring
541 .It Li XX,YY Ns Ic d Ns Li ZZ
542 Delete the range of lines
548 .It Li XX Ns Ic c Ns Li YY
557 .It Li XX,YY Ns Ic c Ns Li ZZ
558 Replace the range of specified lines with the line
560 .It Li XX,YY Ns Ic c Ns Li ZZ,QQ
573 subcommands to convert
577 The line numbers before the action letters pertain to
579 those after pertain to
585 and reading the line in reverse order, one can also
586 determine how to convert
593 pairs (where num1 = num2) are abbreviated as a single
596 .Bl -tag -width /tmp/diff.XXXXXXXX -compact
597 .It Pa /tmp/diff.XXXXXXXX
598 Temporary file used when comparing a device or the standard input.
599 Note that the temporary file is unlinked as soon as it is created
600 so it will not show up in a directory listing.
605 utility exits with one of the following values:
607 .Bl -tag -width Ds -offset indent -compact
609 No differences were found.
611 Differences were found.
620 recursively generating an unified diff and treating files found only in one
621 of those directories as new files:
622 .Bd -literal -offset indent
623 $ diff -ruN /path/to/old_dir /path/to/new_dir
626 Same as above but excluding files matching the expressions
630 .Bd -literal -offset indent
631 $ diff -ruN -x '*.h' -x '*.c' /path/to/old_dir /path/to/new_dir
634 Show a single line indicating if the files differ:
635 .Bd -literal -offset indent
636 $ diff -q /boot/loader.conf /boot/defaults/loader.conf
637 Files /boot/loader.conf and /boot/defaults/loader.conf differ
640 Assuming a file named
642 with the following contents:
643 .Bd -literal -offset indent
644 FreeBSD is an operating system
646 OpenBSD is an operating system
651 excluding from the comparison those lines containing either
655 .Bd -literal -offset indent
656 $ echo "FreeBSD is an operating system" | diff -q -I 'Linux|Open' example.txt -
668 .%A M. Douglas McIlroy
669 .%T "An Algorithm for Differential File Comparison"
670 .%J Computing Science Technical Report
671 .%Q Bell Laboratories 41
677 utility is compliant with the
682 .Op Fl aDdIiLlNnPpqSsTtwXxy
683 are extensions to that specification.