1 .\" $OpenBSD: diff.1,v 1.47 2015/11/24 19:35:41 jmc Exp $ 2 .\" 3 .\" Copyright (c) 1980, 1990, 1993 4 .\" The Regents of the University of California. All rights reserved. 5 .\" 6 .\" Redistribution and use in source and binary forms, with or without 7 .\" modification, are permitted provided that the following conditions 8 .\" are met: 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. 17 .\" 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 28 .\" SUCH DAMAGE. 29 .\" 30 .Dd July 26, 2024 31 .Dt DIFF 1 32 .Os 33 .Sh NAME 34 .Nm diff 35 .Nd differential file and directory comparator 36 .Sh SYNOPSIS 37 .Nm diff 38 .Op Fl aBbdipTtw 39 .Oo 40 .Fl c | e | f | 41 .Fl n | q | u | y 42 .Oc 43 .Op Fl A Ar algo | Fl -algorithm Ar algo 44 .Op Fl -brief 45 .Op Fl -color Ns = Ns Ar when 46 .Op Fl -changed-group-format Ar GFMT 47 .Op Fl -ed 48 .Op Fl -expand-tabs 49 .Op Fl -forward-ed 50 .Op Fl -ignore-all-space 51 .Op Fl -ignore-case 52 .Op Fl -ignore-space-change 53 .Op Fl -initial-tab 54 .Op Fl -minimal 55 .Op Fl -no-dereference 56 .Op Fl -no-ignore-file-name-case 57 .Op Fl -normal 58 .Op Fl -rcs 59 .Op Fl -show-c-function 60 .Op Fl -starting-file 61 .Op Fl -speed-large-files 62 .Op Fl -strip-trailing-cr 63 .Op Fl -tabsize Ar number 64 .Op Fl -text 65 .Op Fl -unified 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 69 .Ar file1 file2 70 .Nm diff 71 .Op Fl aBbdilpTtw 72 .Op Fl A Ar algo | Fl -algorithm Ar algo 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 76 .Op Fl -brief 77 .Op Fl -color Ns = Ns Ar when 78 .Op Fl -changed-group-format Ar GFMT 79 .Op Fl -ed 80 .Op Fl -expand-tabs 81 .Op Fl -forward-ed 82 .Op Fl -ignore-all-space 83 .Op Fl -ignore-case 84 .Op Fl -ignore-space-change 85 .Op Fl -initial-tab 86 .Op Fl -minimal 87 .Op Fl -no-dereference 88 .Op Fl -no-ignore-file-name-case 89 .Op Fl -normal 90 .Op Fl -paginate 91 .Op Fl -rcs 92 .Op Fl -show-c-function 93 .Op Fl -speed-large-files 94 .Op Fl -starting-file 95 .Op Fl -strip-trailing-cr 96 .Op Fl -tabsize Ar number 97 .Op Fl -text 98 .Fl C Ar number | -context Ar number 99 .Ar file1 file2 100 .Nm diff 101 .Op Fl aBbdiltw 102 .Op Fl A Ar algo | Fl -algorithm Ar algo 103 .Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern 104 .Op Fl -brief 105 .Op Fl -color Ns = Ns Ar when 106 .Op Fl -changed-group-format Ar GFMT 107 .Op Fl -ed 108 .Op Fl -expand-tabs 109 .Op Fl -forward-ed 110 .Op Fl -ignore-all-space 111 .Op Fl -ignore-case 112 .Op Fl -ignore-space-change 113 .Op Fl -initial-tab 114 .Op Fl -minimal 115 .Op Fl -no-dereference 116 .Op Fl -no-ignore-file-name-case 117 .Op Fl -normal 118 .Op Fl -paginate 119 .Op Fl -rcs 120 .Op Fl -show-c-function 121 .Op Fl -speed-large-files 122 .Op Fl -starting-file 123 .Op Fl -strip-trailing-cr 124 .Op Fl -tabsize Ar number 125 .Op Fl -text 126 .Fl D Ar string | Fl -ifdef Ar string 127 .Ar file1 file2 128 .Nm diff 129 .Op Fl aBbdilpTtw 130 .Op Fl A Ar algo | Fl -algorithm Ar algo 131 .Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern 132 .Op Fl F Ar pattern | Fl -show-function-line Ar pattern 133 .Op Fl L Ar label | Fl -label Ar label 134 .Op Fl -brief 135 .Op Fl -color Ns = Ns Ar when 136 .Op Fl -changed-group-format Ar GFMT 137 .Op Fl -ed 138 .Op Fl -expand-tabs 139 .Op Fl -forward-ed 140 .Op Fl -ignore-all-space 141 .Op Fl -ignore-case 142 .Op Fl -ignore-space-change 143 .Op Fl -initial-tab 144 .Op Fl -minimal 145 .Op Fl -no-dereference 146 .Op Fl -no-ignore-file-name-case 147 .Op Fl -normal 148 .Op Fl -paginate 149 .Op Fl -rcs 150 .Op Fl -show-c-function 151 .Op Fl -speed-large-files 152 .Op Fl -starting-file 153 .Op Fl -strip-trailing-cr 154 .Op Fl -tabsize Ar number 155 .Op Fl -text 156 .Fl U Ar number | Fl -unified Ar number 157 .Ar file1 file2 158 .Nm diff 159 .Op Fl aBbdilNPprsTtw 160 .Oo 161 .Fl c | e | f | 162 .Fl n | q | u 163 .Oc 164 .Op Fl A Ar algo | Fl -algorithm Ar algo 165 .Op Fl -brief 166 .Op Fl -color Ns = Ns Ar when 167 .Op Fl -changed-group-format Ar GFMT 168 .Op Fl -context 169 .Op Fl -ed 170 .Op Fl -expand-tabs 171 .Op Fl -forward-ed 172 .Op Fl -ignore-all-space 173 .Op Fl -ignore-case 174 .Op Fl -ignore-space-change 175 .Op Fl -initial-tab 176 .Op Fl -minimal 177 .Op Fl -new-file 178 .Op Fl -no-dereference 179 .Op Fl -no-ignore-file-name-case 180 .Op Fl -normal 181 .Op Fl -paginate 182 .Op Fl -rcs 183 .Op Fl -recursive 184 .Op Fl -report-identical-files 185 .Op Fl -show-c-function 186 .Op Fl -speed-large-files 187 .Op Fl -strip-trailing-cr 188 .Op Fl -tabsize Ar number 189 .Op Fl -text 190 .Op Fl -unidirectional-new-file 191 .Op Fl -unified 192 .Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern 193 .Op Fl F Ar pattern | Fl -show-function-line Ar pattern 194 .Bk -words 195 .Op Fl L Ar label | Fl -label Ar label 196 .Op Fl S Ar name | Fl -starting-file Ar name 197 .Op Fl X Ar file | Fl -exclude-from Ar file 198 .Op Fl x Ar pattern | Fl -exclude Ar pattern 199 .Ek 200 .Ar dir1 dir2 201 .Nm diff 202 .Op Fl aBbditwW 203 .Op Fl -color Ns = Ns Ar when 204 .Op Fl -expand-tabs 205 .Op Fl -ignore-all-space 206 .Op Fl -ignore-blank-lines 207 .Op Fl -ignore-case 208 .Op Fl -minimal 209 .Op Fl -no-dereference 210 .Op Fl -no-ignore-file-name-case 211 .Op Fl -strip-trailing-cr 212 .Op Fl -suppress-common-lines 213 .Op Fl -tabsize Ar number 214 .Op Fl -text 215 .Op Fl -width 216 .Fl y | Fl -side-by-side 217 .Ar file1 file2 218 .Nm diff 219 .Op Fl -help 220 .Op Fl -version 221 .Sh DESCRIPTION 222 The 223 .Nm 224 utility compares the contents of 225 .Ar file1 226 and 227 .Ar file2 228 and writes to the standard output the list of changes necessary to 229 convert one file into the other. 230 No output is produced if the files are identical. 231 .Pp 232 Output options (mutually exclusive): 233 .Bl -tag -width Ds 234 .It Fl C Ar number Fl -context Ar number 235 Like 236 .Fl c 237 but produces a diff with 238 .Ar number 239 lines of context. 240 .It Fl c 241 Produces a diff with 3 lines of context. 242 With 243 .Fl c 244 the output format is modified slightly: 245 the output begins with identification of the files involved and 246 their creation dates and then each change is separated 247 by a line with fifteen 248 .Li * Ns 's . 249 The lines removed from 250 .Ar file1 251 are marked with 252 .Sq \&-\ \& ; 253 those added to 254 .Ar file2 255 are marked 256 .Sq +\ \& . 257 Lines which are changed from one file to the other are marked in 258 both files with 259 .Sq !\ \& . 260 Changes which lie within 3 lines of each other are grouped together on 261 output. 262 .It Fl D Ar string Fl -ifdef Ar string 263 Creates a merged version of 264 .Ar file1 265 and 266 .Ar file2 267 on the standard output, with C preprocessor controls included so that 268 a compilation of the result without defining 269 .Ar string 270 is equivalent to compiling 271 .Ar file1 , 272 while defining 273 .Ar string 274 will yield 275 .Ar file2 . 276 .It Fl e -ed 277 Produces output in a form suitable as input for the editor utility, 278 .Xr ed 1 , 279 which can then be used to convert file1 into file2. 280 .Pp 281 Extra commands are added to the output when comparing directories with 282 .Fl e , 283 so that the result is a 284 .Xr sh 1 285 script for converting text files which are common to the two directories 286 from their state in 287 .Ar dir1 288 to their state in 289 .Ar dir2 . 290 Note that when comparing directories with 291 .Fl e , 292 the resulting file may no longer be interpreted as an 293 .Xr ed 1 294 script. 295 Output is added to indicate which file each set of 296 .Xr ed 1 297 commands applies to. 298 These hunks can be manually extracted to produce an 299 .Xr ed 1 300 script, which can also be applied with 301 .Xr patch 1 . 302 .It Fl f -forward-ed 303 Identical output to that of the 304 .Fl e 305 flag, but in reverse order. 306 It cannot be digested by 307 .Xr ed 1 . 308 .It Fl -help 309 This option prints a summary to stdout and exits with status 0. 310 .It Fl n 311 Produces a script similar to that of 312 .Fl e , 313 but in the opposite order and with a count of changed lines on each 314 insert or delete command. 315 This is the form used by rcsdiff. 316 .It Fl q -brief 317 Just print a line when the files differ. 318 Does not output a list of changes. 319 .It Fl U Ar number Fl -unified Ar number 320 Like 321 .Fl u 322 but produces a diff with 323 .Ar number 324 lines of context. 325 .It Fl u 326 Produces a 327 .Em unified 328 diff with 3 lines of context. 329 A unified diff is similar to the context diff produced by the 330 .Fl c 331 option. 332 However, unlike with 333 .Fl c , 334 all lines to be changed (added and/or removed) are present in 335 a single section. 336 .It Fl -version 337 This option prints a version string to stdout and exits with status 0. 338 .It Fl y Fl -side-by-side 339 Output in two columns with a marker between them. 340 The marker can be one 341 of the following: 342 .Pp 343 .Bl -tag -width Ds -offset indent -compact 344 .It space 345 Corresponding lines are identical. 346 .It '|' 347 Corresponding lines are different. 348 .It '<' 349 Files differ and only the first file contains the line. 350 .It '>' 351 Files differ and only the second file contains the line. 352 .El 353 .El 354 .Pp 355 Comparison options: 356 .Bl -tag -width Ds 357 .It Fl A Ar algo, Fl -algorithm Ar algo 358 Configure the algorithm used when comparing files. 359 .Nm 360 supports 3 algorithms: 361 .Pp 362 .Bl -tag -width Ds -compact 363 .It Cm myers 364 The Myers diff algorithm finds the shortest edit which transforms one 365 input into the other. 366 It generally runs in O(N+D\(S2) time, requiring O(N) space, where N is 367 the sum of the lengths of the inputs and D is the length of the 368 difference between them, with a theoretical O(N\(pcD) worst case. 369 If it encounters worst-case input, the implementation used by 370 .Nm 371 falls back to a less optimal but faster algorithm. 372 .It Cm patience 373 The Patience variant of the Myers algorithm attempts to create more 374 aesthetically pleasing diff output by logically grouping lines. 375 .It Cm stone 376 The Stone algorithm (commonly known as Hunt-McIlroy or Hunt-Szymanski) 377 looks for the longest common subsequence between compared files. 378 Stone encounters worst case performance when there are long common 379 subsequences. 380 In large files this can lead to a significant performance impact. 381 The Stone algorithm is maintained for compatibility. 382 .El 383 .Pp 384 The 385 .Nm 386 utility defaults to the Myers algorithm, but will fall back to the 387 Stone algorithm if the input or output options are not supported by 388 the Myers implementation. 389 .It Fl a -text 390 Treat all files as ASCII text. 391 Normally 392 .Nm 393 will simply print 394 .Dq Binary files ... differ 395 if files contain binary characters. 396 Use of this option forces 397 .Nm 398 to produce a diff. 399 .It Fl B Fl -ignore-blank-lines 400 Causes chunks that include only blank lines to be ignored. 401 .It Fl b -ignore-space-change 402 Causes trailing blanks (spaces and tabs) to be ignored, and other 403 strings of blanks to compare equal. 404 .It Fl -color= Ns Oo Ar when Oc 405 Color the additions green, and removals red, or the value in the 406 .Ev DIFFCOLORS 407 environment variable. 408 The possible values of 409 .Ar when 410 are 411 .Dq Cm never , 412 .Dq Cm always 413 and 414 .Dq Cm auto . 415 .Cm auto 416 will use color if the output is a tty and the 417 .Ev COLORTERM 418 environment variable is set to a non-empty string. 419 .It Fl d -minimal 420 Try very hard to produce a diff as small as possible. 421 This may consume a lot of processing power and memory when processing 422 large files with many changes. 423 .It Fl F Ar pattern, Fl -show-function-line Ar pattern 424 Like 425 .Fl p, 426 but display the last line that matches provided pattern. 427 .It Fl I Ar pattern Fl -ignore-matching-lines Ar pattern 428 Ignores changes, insertions, and deletions whose lines match the 429 extended regular expression 430 .Ar pattern . 431 Multiple 432 .Fl I 433 patterns may be specified. 434 All lines in the change must match some pattern for the change to be 435 ignored. 436 See 437 .Xr re_format 7 438 for more information on regular expression patterns. 439 .It Fl i -ignore-case 440 Ignores the case of letters. 441 E.g., 442 .Dq A 443 will compare equal to 444 .Dq a . 445 .It Fl l -paginate 446 Pass the output through 447 .Xr pr 1 448 to paginate it. 449 .It Fl L Ar label Fl -label Ar label 450 Print 451 .Ar label 452 instead of the first (and second, if this option is specified twice) 453 file name and time in the context or unified diff header. 454 .It Fl p -show-c-function 455 With unified and context diffs, show with each change 456 the first 40 characters of the last line before the context beginning 457 with a letter, an underscore or a dollar sign. 458 For C and Objective-C source code following standard layout conventions, this 459 will show the prototype of the function the change applies to. 460 .It Fl T -initial-tab 461 Print a tab rather than a space before the rest of the line for the 462 normal, context or unified output formats. 463 This makes the alignment of tabs in the line consistent. 464 .It Fl t -expand-tabs 465 Will expand tabs in output lines. 466 Normal or 467 .Fl c 468 output adds character(s) to the front of each line which may screw up 469 the indentation of the original source lines and make the output listing 470 difficult to interpret. 471 This option will preserve the original source's indentation. 472 .It Fl w -ignore-all-space 473 Is similar to 474 .Fl b -ignore-space-change 475 but causes whitespace (blanks and tabs) to be totally ignored. 476 E.g., 477 .Dq if (\ \&a == b \&) 478 will compare equal to 479 .Dq if(a==b) . 480 .It Fl W Ar number Fl -width Ar number 481 Output at most 482 .Ar number 483 columns when using side by side format. 484 The default value is 130. 485 Note that unless 486 .It Fl t 487 was specified, 488 .Nm 489 will always align the second column to a tab stop, so values of 490 .Fl -width 491 smaller than approximately five times the value of 492 .Fl -tabsize 493 may yield surprising results. 494 .It Fl -changed-group-format Ar GFMT 495 Format input groups in the provided 496 .Pp 497 the format is a string with special keywords: 498 .Bl -tag -width %< 499 .It %< 500 lines from FILE1 501 .It %< 502 lines from FILE2 503 .El 504 .It Fl -ignore-file-name-case 505 ignore case when comparing file names 506 .It Fl -no-dereference 507 do not follow symbolic links 508 .It Fl -no-ignore-file-name-case 509 do not ignore case when comparing file names (default) 510 .It Fl -normal 511 default diff output 512 .It Fl -speed-large-files 513 stub option for compatibility with GNU diff 514 .It Fl -strip-trailing-cr 515 strip carriage return on input files 516 .It Fl -suppress-common-lines 517 Do not output common lines when using the side by side format 518 .It Fl -tabsize Ar number 519 Number of spaces representing a tab (default 8) 520 .El 521 .Pp 522 Directory comparison options: 523 .Bl -tag -width Ds 524 .It Fl N -new-file 525 If a file is found in only one directory, act as if it was found in the 526 other directory too but was of zero size. 527 .It Fl P -unidirectional-new-file 528 If a file is found only in 529 .Ar dir2 , 530 act as if it was found in 531 .Ar dir1 532 too but was of zero size. 533 .It Fl r -recursive 534 Causes application of 535 .Nm 536 recursively to common subdirectories encountered. 537 .It Fl S Ar name Fl -starting-file Ar name 538 Re-starts a directory 539 .Nm 540 in the middle, beginning with file 541 .Ar name . 542 .It Fl s -report-identical-files 543 Causes 544 .Nm 545 to report files which are the same, which are otherwise not mentioned. 546 .It Fl X Ar file Fl -exclude-from Ar file 547 Exclude files and subdirectories from comparison whose basenames match 548 lines in 549 .Ar file . 550 Multiple 551 .Fl X 552 options may be specified. 553 .It Fl x Ar pattern Fl -exclude Ar pattern 554 Exclude files and subdirectories from comparison whose basenames match 555 .Ar pattern . 556 Patterns are matched using shell-style globbing via 557 .Xr fnmatch 3 . 558 Multiple 559 .Fl x 560 options may be specified. 561 .El 562 .Pp 563 If both arguments are directories, 564 .Nm 565 sorts the contents of the directories by name, and then runs the 566 regular file 567 .Nm 568 algorithm, producing a change list, 569 on text files which are different. 570 Binary files which differ, 571 common subdirectories, and files which appear in only one directory 572 are described as such. 573 In directory mode only regular files and directories are compared. 574 If a non-regular file such as a device special file or FIFO is encountered, 575 a diagnostic message is printed. 576 .Pp 577 If only one of 578 .Ar file1 579 and 580 .Ar file2 581 is a directory, 582 .Nm 583 is applied to the non-directory file and the file contained in 584 the directory file with a filename that is the same as the 585 last component of the non-directory file. 586 .Pp 587 If either 588 .Ar file1 589 or 590 .Ar file2 591 is 592 .Sq - , 593 the standard input is 594 used in its place. 595 .Ss Output Style 596 The default (without 597 .Fl e , 598 .Fl c , 599 or 600 .Fl n -rcs 601 .\" -C 602 options) 603 output contains lines of these forms, where 604 .Va XX , YY , ZZ , QQ 605 are line numbers respective of file order. 606 .Pp 607 .Bl -tag -width "XX,YYcZZ,QQ" -compact 608 .It Li XX Ns Ic a Ns Li YY 609 At (the end of) line 610 .Va XX 611 of 612 .Ar file1 , 613 append the contents 614 of line 615 .Va YY 616 of 617 .Ar file2 618 to make them equal. 619 .It Li XX Ns Ic a Ns Li YY,ZZ 620 Same as above, but append the range of lines, 621 .Va YY 622 through 623 .Va ZZ 624 of 625 .Ar file2 626 to line 627 .Va XX 628 of file1. 629 .It Li XX Ns Ic d Ns Li YY 630 At line 631 .Va XX 632 delete 633 the line. 634 The value 635 .Va YY 636 tells to which line the change would bring 637 .Ar file1 638 in line with 639 .Ar file2 . 640 .It Li XX,YY Ns Ic d Ns Li ZZ 641 Delete the range of lines 642 .Va XX 643 through 644 .Va YY 645 in 646 .Ar file1 . 647 .It Li XX Ns Ic c Ns Li YY 648 Change the line 649 .Va XX 650 in 651 .Ar file1 652 to the line 653 .Va YY 654 in 655 .Ar file2 . 656 .It Li XX,YY Ns Ic c Ns Li ZZ 657 Replace the range of specified lines with the line 658 .Va ZZ . 659 .It Li XX,YY Ns Ic c Ns Li ZZ,QQ 660 Replace the range 661 .Va XX , Ns Va YY 662 from 663 .Ar file1 664 with the range 665 .Va ZZ , Ns Va QQ 666 from 667 .Ar file2 . 668 .El 669 .Pp 670 These lines resemble 671 .Xr ed 1 672 subcommands to convert 673 .Ar file1 674 into 675 .Ar file2 . 676 The line numbers before the action letters pertain to 677 .Ar file1 ; 678 those after pertain to 679 .Ar file2 . 680 Thus, by exchanging 681 .Ic a 682 for 683 .Ic d 684 and reading the line in reverse order, one can also 685 determine how to convert 686 .Ar file2 687 into 688 .Ar file1 . 689 As in 690 .Xr ed 1 , 691 identical 692 pairs (where num1 = num2) are abbreviated as a single 693 number. 694 .Sh ENVIRONMENT 695 .Bl -tag -width DIFFCOLORS 696 .It Ev DIFFCOLORS 697 The value of this variable is the form 698 .Ar add Ns : Ns Ar rm , 699 where 700 .Ar add 701 is the ASCII escape sequence for additions and 702 .Ar rm 703 is the ASCII escape sequence for deletions. 704 If this is unset, 705 .Nm 706 uses green for additions and red for removals. 707 .El 708 .Sh FILES 709 .Bl -tag -width /tmp/diff.XXXXXXXX -compact 710 .It Pa /tmp/diff.XXXXXXXX 711 Temporary file used when comparing a device or the standard input. 712 Note that the temporary file is unlinked as soon as it is created 713 so it will not show up in a directory listing. 714 .El 715 .Sh EXIT STATUS 716 The 717 .Nm 718 utility exits with one of the following values: 719 .Pp 720 .Bl -tag -width Ds -offset indent -compact 721 .It 0 722 No differences were found. 723 .It 1 724 Differences were found. 725 .It >1 726 An error occurred. 727 .El 728 .Pp 729 The 730 .Fl -help 731 and 732 .Fl -version 733 options exit with a status of 0. 734 .Sh EXAMPLES 735 Compare 736 .Pa old_dir 737 and 738 .Pa new_dir 739 recursively generating an unified diff and treating files found only in one 740 of those directories as new files: 741 .Bd -literal -offset indent 742 $ diff -ruN /path/to/old_dir /path/to/new_dir 743 .Ed 744 .Pp 745 Same as above but excluding files matching the expressions 746 .Dq *.h 747 and 748 .Dq *.c : 749 .Bd -literal -offset indent 750 $ diff -ruN -x '*.h' -x '*.c' /path/to/old_dir /path/to/new_dir 751 .Ed 752 .Pp 753 Show a single line indicating if the files differ: 754 .Bd -literal -offset indent 755 $ diff -q /boot/loader.conf /boot/defaults/loader.conf 756 Files /boot/loader.conf and /boot/defaults/loader.conf differ 757 .Ed 758 .Pp 759 Assuming a file named 760 .Pa example.txt 761 with the following contents: 762 .Bd -literal -offset indent 763 FreeBSD is an operating system 764 Linux is a kernel 765 OpenBSD is an operating system 766 .Ed 767 .Pp 768 Compare stdin with 769 .Pa example.txt 770 excluding from the comparison those lines containing either 771 .Qq Linux 772 or 773 .Qq Open : 774 .Bd -literal -offset indent 775 $ echo "FreeBSD is an operating system" | diff -q -I 'Linux|Open' example.txt - 776 .Ed 777 .Sh SEE ALSO 778 .Xr cmp 1 , 779 .Xr comm 1 , 780 .Xr diff3 1 , 781 .Xr ed 1 , 782 .Xr patch 1 , 783 .Xr pr 1 , 784 .Xr sdiff 1 785 .Rs 786 .%A James W. Hunt 787 .%A M. Douglas McIlroy 788 .%T "An Algorithm for Differential File Comparison" 789 .%J Computing Science Technical Report 790 .%Q Bell Laboratories 41 791 .%D June 1976 792 .Re 793 .Sh STANDARDS 794 The 795 .Nm 796 utility is compliant with the 797 .St -p1003.1-2008 798 specification. 799 .Pp 800 The flags 801 .Op Fl AaDdIiLlNnPpqSsTtwXxy 802 are extensions to that specification. 803 .Sh HISTORY 804 A 805 .Nm 806 command appeared in 807 .At v6 . 808 The 809 .Nm 810 implementation used in 811 .Fx 812 was GNU diff until 813 .Fx 11.4 . 814 This was replaced in 815 .Fx 12.0 816 by a BSD-licensed implementation written by 817 .An Todd Miller . 818 Some GNUisms were lost in the process. 819 .Pp 820 libdiff was imported from the Game of Trees version control system and default 821 algorithm was changed to Myers for FreeBSD 15. 822