| 1 | This is diff.info, produced by makeinfo version 4.2 from diff.texi.
|
|---|
| 2 |
|
|---|
| 3 | This manual is for GNU Diffutils (version 2.8.1, 5 April 2002), and
|
|---|
| 4 | documents the GNU `diff', `diff3', `sdiff', and `cmp' commands for
|
|---|
| 5 | showing the differences between files and the GNU `patch' command for
|
|---|
| 6 | using their output to update files.
|
|---|
| 7 |
|
|---|
| 8 | Copyright (C) 1992, 1993, 1994, 1998, 2001, 2002 Free Software
|
|---|
| 9 | Foundation, Inc.
|
|---|
| 10 |
|
|---|
| 11 | Permission is granted to copy, distribute and/or modify this
|
|---|
| 12 | document under the terms of the GNU Free Documentation License,
|
|---|
| 13 | Version 1.1 or any later version published by the Free Software
|
|---|
| 14 | Foundation; with no Invariant Sections, with the Front-Cover texts
|
|---|
| 15 | being "A GNU Manual," and with the Back-Cover Texts as in (a)
|
|---|
| 16 | below. A copy of the license is included in the section entitled
|
|---|
| 17 | "GNU Free Documentation License."
|
|---|
| 18 |
|
|---|
| 19 | (a) The FSF's Back-Cover Text is: "You have freedom to copy and
|
|---|
| 20 | modify this GNU Manual, like GNU software. Copies published by
|
|---|
| 21 | the Free Software Foundation raise funds for GNU development."
|
|---|
| 22 |
|
|---|
| 23 | INFO-DIR-SECTION Individual utilities
|
|---|
| 24 | START-INFO-DIR-ENTRY
|
|---|
| 25 | * cmp: (diff)Invoking cmp. Compare 2 files byte by byte.
|
|---|
| 26 | * diff: (diff)Invoking diff. Compare 2 files line by line.
|
|---|
| 27 | * diff3: (diff)Invoking diff3. Compare 3 files line by line.
|
|---|
| 28 | * patch: (diff)Invoking patch. Apply a patch to a file.
|
|---|
| 29 | * sdiff: (diff)Invoking sdiff. Merge 2 files side-by-side.
|
|---|
| 30 | END-INFO-DIR-ENTRY
|
|---|
| 31 |
|
|---|
| 32 | INFO-DIR-SECTION GNU packages
|
|---|
| 33 | START-INFO-DIR-ENTRY
|
|---|
| 34 | * Diff: (diff). Comparing and merging files.
|
|---|
| 35 | END-INFO-DIR-ENTRY
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 | File: diff.info, Node: Top, Next: Overview, Up: (dir)
|
|---|
| 39 |
|
|---|
| 40 | Comparing and Merging Files
|
|---|
| 41 | ***************************
|
|---|
| 42 |
|
|---|
| 43 | This manual is for GNU Diffutils (version 2.8.1, 5 April 2002), and
|
|---|
| 44 | documents the GNU `diff', `diff3', `sdiff', and `cmp' commands for
|
|---|
| 45 | showing the differences between files and the GNU `patch' command for
|
|---|
| 46 | using their output to update files.
|
|---|
| 47 |
|
|---|
| 48 | Copyright (C) 1992, 1993, 1994, 1998, 2001, 2002 Free Software
|
|---|
| 49 | Foundation, Inc.
|
|---|
| 50 |
|
|---|
| 51 | Permission is granted to copy, distribute and/or modify this
|
|---|
| 52 | document under the terms of the GNU Free Documentation License,
|
|---|
| 53 | Version 1.1 or any later version published by the Free Software
|
|---|
| 54 | Foundation; with no Invariant Sections, with the Front-Cover texts
|
|---|
| 55 | being "A GNU Manual," and with the Back-Cover Texts as in (a)
|
|---|
| 56 | below. A copy of the license is included in the section entitled
|
|---|
| 57 | "GNU Free Documentation License."
|
|---|
| 58 |
|
|---|
| 59 | (a) The FSF's Back-Cover Text is: "You have freedom to copy and
|
|---|
| 60 | modify this GNU Manual, like GNU software. Copies published by
|
|---|
| 61 | the Free Software Foundation raise funds for GNU development."
|
|---|
| 62 |
|
|---|
| 63 | * Menu:
|
|---|
| 64 |
|
|---|
| 65 | * Overview:: Preliminary information.
|
|---|
| 66 | * Comparison:: What file comparison means.
|
|---|
| 67 |
|
|---|
| 68 | * Output Formats:: Formats for two-way difference reports.
|
|---|
| 69 | * Incomplete Lines:: Lines that lack trailing newlines.
|
|---|
| 70 | * Comparing Directories:: Comparing files and directories.
|
|---|
| 71 | * Adjusting Output:: Making `diff' output prettier.
|
|---|
| 72 | * diff Performance:: Making `diff' smarter or faster.
|
|---|
| 73 |
|
|---|
| 74 | * Comparing Three Files:: Formats for three-way difference reports.
|
|---|
| 75 | * diff3 Merging:: Merging from a common ancestor.
|
|---|
| 76 |
|
|---|
| 77 | * Interactive Merging:: Interactive merging with `sdiff'.
|
|---|
| 78 |
|
|---|
| 79 | * Merging with patch:: Using `patch' to change old files into new ones.
|
|---|
| 80 | * Making Patches:: Tips for making and using patch distributions.
|
|---|
| 81 |
|
|---|
| 82 | * Invoking cmp:: Compare two files byte by byte.
|
|---|
| 83 | * Invoking diff:: Compare two files line by line.
|
|---|
| 84 | * Invoking diff3:: Compare three files line by line.
|
|---|
| 85 | * Invoking patch:: Apply a diff file to an original.
|
|---|
| 86 | * Invoking sdiff:: Side-by-side merge of file differences.
|
|---|
| 87 |
|
|---|
| 88 | * Standards conformance:: Conformance to the POSIX standard.
|
|---|
| 89 | * Projects:: If you've found a bug or other shortcoming.
|
|---|
| 90 |
|
|---|
| 91 | * Copying This Manual:: How to make copies of this manual.
|
|---|
| 92 | * Index:: Index.
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 | File: diff.info, Node: Overview, Next: Comparison, Prev: Top, Up: Top
|
|---|
| 96 |
|
|---|
| 97 | Overview
|
|---|
| 98 | ********
|
|---|
| 99 |
|
|---|
| 100 | Computer users often find occasion to ask how two files differ.
|
|---|
| 101 | Perhaps one file is a newer version of the other file. Or maybe the
|
|---|
| 102 | two files started out as identical copies but were changed by different
|
|---|
| 103 | people.
|
|---|
| 104 |
|
|---|
| 105 | You can use the `diff' command to show differences between two
|
|---|
| 106 | files, or each corresponding file in two directories. `diff' outputs
|
|---|
| 107 | differences between files line by line in any of several formats,
|
|---|
| 108 | selectable by command line options. This set of differences is often
|
|---|
| 109 | called a "diff" or "patch". For files that are identical, `diff'
|
|---|
| 110 | normally produces no output; for binary (non-text) files, `diff'
|
|---|
| 111 | normally reports only that they are different.
|
|---|
| 112 |
|
|---|
| 113 | You can use the `cmp' command to show the byte and line numbers
|
|---|
| 114 | where two files differ. `cmp' can also show all the bytes that differ
|
|---|
| 115 | between the two files, side by side. A way to compare two files
|
|---|
| 116 | character by character is the Emacs command `M-x compare-windows'.
|
|---|
| 117 | *Note Other Window: (emacs)Other Window, for more information on that
|
|---|
| 118 | command.
|
|---|
| 119 |
|
|---|
| 120 | You can use the `diff3' command to show differences among three
|
|---|
| 121 | files. When two people have made independent changes to a common
|
|---|
| 122 | original, `diff3' can report the differences between the original and
|
|---|
| 123 | the two changed versions, and can produce a merged file that contains
|
|---|
| 124 | both persons' changes together with warnings about conflicts.
|
|---|
| 125 |
|
|---|
| 126 | You can use the `sdiff' command to merge two files interactively.
|
|---|
| 127 |
|
|---|
| 128 | You can use the set of differences produced by `diff' to distribute
|
|---|
| 129 | updates to text files (such as program source code) to other people.
|
|---|
| 130 | This method is especially useful when the differences are small compared
|
|---|
| 131 | to the complete files. Given `diff' output, you can use the `patch'
|
|---|
| 132 | program to update, or "patch", a copy of the file. If you think of
|
|---|
| 133 | `diff' as subtracting one file from another to produce their
|
|---|
| 134 | difference, you can think of `patch' as adding the difference to one
|
|---|
| 135 | file to reproduce the other.
|
|---|
| 136 |
|
|---|
| 137 | This manual first concentrates on making diffs, and later shows how
|
|---|
| 138 | to use diffs to update files.
|
|---|
| 139 |
|
|---|
| 140 | GNU `diff' was written by Paul Eggert, Mike Haertel, David Hayes,
|
|---|
| 141 | Richard Stallman, and Len Tower. Wayne Davison designed and
|
|---|
| 142 | implemented the unified output format. The basic algorithm is described
|
|---|
| 143 | in "An O(ND) Difference Algorithm and its Variations", Eugene W. Myers,
|
|---|
| 144 | `Algorithmica' Vol. 1 No. 2, 1986, pp. 251-266; and in "A File
|
|---|
| 145 | Comparison Program", Webb Miller and Eugene W. Myers,
|
|---|
| 146 | `Software--Practice and Experience' Vol. 15 No. 11, 1985, pp. 1025-1040.
|
|---|
| 147 | The algorithm was independently discovered as described in "Algorithms
|
|---|
| 148 | for Approximate String Matching", E. Ukkonen, `Information and Control'
|
|---|
| 149 | Vol. 64, 1985, pp. 100-118.
|
|---|
| 150 |
|
|---|
| 151 | GNU `diff3' was written by Randy Smith. GNU `sdiff' was written by
|
|---|
| 152 | Thomas Lord. GNU `cmp' was written by Torbjorn Granlund and David
|
|---|
| 153 | MacKenzie.
|
|---|
| 154 |
|
|---|
| 155 | `patch' was written mainly by Larry Wall and Paul Eggert; several
|
|---|
| 156 | GNU enhancements were contributed by Wayne Davison and David MacKenzie.
|
|---|
| 157 | Parts of this manual are adapted from a manual page written by Larry
|
|---|
| 158 | Wall, with his permission.
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 | File: diff.info, Node: Comparison, Next: Output Formats, Prev: Overview, Up: Top
|
|---|
| 162 |
|
|---|
| 163 | What Comparison Means
|
|---|
| 164 | *********************
|
|---|
| 165 |
|
|---|
| 166 | There are several ways to think about the differences between two
|
|---|
| 167 | files. One way to think of the differences is as a series of lines
|
|---|
| 168 | that were deleted from, inserted in, or changed in one file to produce
|
|---|
| 169 | the other file. `diff' compares two files line by line, finds groups of
|
|---|
| 170 | lines that differ, and reports each group of differing lines. It can
|
|---|
| 171 | report the differing lines in several formats, which have different
|
|---|
| 172 | purposes.
|
|---|
| 173 |
|
|---|
| 174 | GNU `diff' can show whether files are different without detailing
|
|---|
| 175 | the differences. It also provides ways to suppress certain kinds of
|
|---|
| 176 | differences that are not important to you. Most commonly, such
|
|---|
| 177 | differences are changes in the amount of white space between words or
|
|---|
| 178 | lines. `diff' also provides ways to suppress differences in alphabetic
|
|---|
| 179 | case or in lines that match a regular expression that you provide.
|
|---|
| 180 | These options can accumulate; for example, you can ignore changes in
|
|---|
| 181 | both white space and alphabetic case.
|
|---|
| 182 |
|
|---|
| 183 | Another way to think of the differences between two files is as a
|
|---|
| 184 | sequence of pairs of bytes that can be either identical or different.
|
|---|
| 185 | `cmp' reports the differences between two files byte by byte, instead
|
|---|
| 186 | of line by line. As a result, it is often more useful than `diff' for
|
|---|
| 187 | comparing binary files. For text files, `cmp' is useful mainly when
|
|---|
| 188 | you want to know only whether two files are identical, or whether one
|
|---|
| 189 | file is a prefix of the other.
|
|---|
| 190 |
|
|---|
| 191 | To illustrate the effect that considering changes byte by byte can
|
|---|
| 192 | have compared with considering them line by line, think of what happens
|
|---|
| 193 | if a single newline character is added to the beginning of a file. If
|
|---|
| 194 | that file is then compared with an otherwise identical file that lacks
|
|---|
| 195 | the newline at the beginning, `diff' will report that a blank line has
|
|---|
| 196 | been added to the file, while `cmp' will report that almost every byte
|
|---|
| 197 | of the two files differs.
|
|---|
| 198 |
|
|---|
| 199 | `diff3' normally compares three input files line by line, finds
|
|---|
| 200 | groups of lines that differ, and reports each group of differing lines.
|
|---|
| 201 | Its output is designed to make it easy to inspect two different sets of
|
|---|
| 202 | changes to the same file.
|
|---|
| 203 |
|
|---|
| 204 | * Menu:
|
|---|
| 205 |
|
|---|
| 206 | * Hunks:: Groups of differing lines.
|
|---|
| 207 | * White Space:: Suppressing differences in white space.
|
|---|
| 208 | * Blank Lines:: Suppressing differences in blank lines.
|
|---|
| 209 | * Case Folding:: Suppressing differences in alphabetic case.
|
|---|
| 210 | * Specified Folding:: Suppressing differences that match regular expressions.
|
|---|
| 211 | * Brief:: Summarizing which files are different.
|
|---|
| 212 | * Binary:: Comparing binary files or forcing text comparisons.
|
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 | File: diff.info, Node: Hunks, Next: White Space, Up: Comparison
|
|---|
| 216 |
|
|---|
| 217 | Hunks
|
|---|
| 218 | =====
|
|---|
| 219 |
|
|---|
| 220 | When comparing two files, `diff' finds sequences of lines common to
|
|---|
| 221 | both files, interspersed with groups of differing lines called "hunks".
|
|---|
| 222 | Comparing two identical files yields one sequence of common lines and
|
|---|
| 223 | no hunks, because no lines differ. Comparing two entirely different
|
|---|
| 224 | files yields no common lines and one large hunk that contains all lines
|
|---|
| 225 | of both files. In general, there are many ways to match up lines
|
|---|
| 226 | between two given files. `diff' tries to minimize the total hunk size
|
|---|
| 227 | by finding large sequences of common lines interspersed with small
|
|---|
| 228 | hunks of differing lines.
|
|---|
| 229 |
|
|---|
| 230 | For example, suppose the file `F' contains the three lines `a', `b',
|
|---|
| 231 | `c', and the file `G' contains the same three lines in reverse order
|
|---|
| 232 | `c', `b', `a'. If `diff' finds the line `c' as common, then the command
|
|---|
| 233 | `diff F G' produces this output:
|
|---|
| 234 |
|
|---|
| 235 | 1,2d0
|
|---|
| 236 | < a
|
|---|
| 237 | < b
|
|---|
| 238 | 3a2,3
|
|---|
| 239 | > b
|
|---|
| 240 | > a
|
|---|
| 241 |
|
|---|
| 242 | But if `diff' notices the common line `b' instead, it produces this
|
|---|
| 243 | output:
|
|---|
| 244 |
|
|---|
| 245 | 1c1
|
|---|
| 246 | < a
|
|---|
| 247 | ---
|
|---|
| 248 | > c
|
|---|
| 249 | 3c3
|
|---|
| 250 | < c
|
|---|
| 251 | ---
|
|---|
| 252 | > a
|
|---|
| 253 |
|
|---|
| 254 | It is also possible to find `a' as the common line. `diff' does not
|
|---|
| 255 | always find an optimal matching between the files; it takes shortcuts
|
|---|
| 256 | to run faster. But its output is usually close to the shortest
|
|---|
| 257 | possible. You can adjust this tradeoff with the `--minimal' option
|
|---|
| 258 | (*note diff Performance::).
|
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 | File: diff.info, Node: White Space, Next: Blank Lines, Prev: Hunks, Up: Comparison
|
|---|
| 262 |
|
|---|
| 263 | Suppressing Differences in Blank and Tab Spacing
|
|---|
| 264 | ================================================
|
|---|
| 265 |
|
|---|
| 266 | The `-E' and `--ignore-tab-expansion' options ignore the distinction
|
|---|
| 267 | between tabs and spaces on input. A tab is considered to be equivalent
|
|---|
| 268 | to the number of spaces to the next tab stop. `diff' assumes that tab
|
|---|
| 269 | stops are set every 8 print columns.
|
|---|
| 270 |
|
|---|
| 271 | The `-b' and `--ignore-space-change' options are stronger. They
|
|---|
| 272 | ignore white space at line end, and consider all other sequences of one
|
|---|
| 273 | or more white space characters to be equivalent. With these options,
|
|---|
| 274 | `diff' considers the following two lines to be equivalent, where `$'
|
|---|
| 275 | denotes the line end:
|
|---|
| 276 |
|
|---|
| 277 | Here lyeth muche rychnesse in lytell space. -- John Heywood$
|
|---|
| 278 | Here lyeth muche rychnesse in lytell space. -- John Heywood $
|
|---|
| 279 |
|
|---|
| 280 | The `-w' and `--ignore-all-space' options are stronger still. They
|
|---|
| 281 | ignore difference even if one line has white space where the other line
|
|---|
| 282 | has none. "White space" characters include tab, newline, vertical tab,
|
|---|
| 283 | form feed, carriage return, and space; some locales may define
|
|---|
| 284 | additional characters to be white space. With these options, `diff'
|
|---|
| 285 | considers the following two lines to be equivalent, where `$' denotes
|
|---|
| 286 | the line end and `^M' denotes a carriage return:
|
|---|
| 287 |
|
|---|
| 288 | Here lyeth muche rychnesse in lytell space.-- John Heywood$
|
|---|
| 289 | He relyeth much erychnes seinly tells pace. --John Heywood ^M$
|
|---|
| 290 |
|
|---|
| 291 |
|
|---|
| 292 | File: diff.info, Node: Blank Lines, Next: Case Folding, Prev: White Space, Up: Comparison
|
|---|
| 293 |
|
|---|
| 294 | Suppressing Differences in Blank Lines
|
|---|
| 295 | ======================================
|
|---|
| 296 |
|
|---|
| 297 | The `-B' and `--ignore-blank-lines' options ignore insertions or
|
|---|
| 298 | deletions of blank lines. These options affect only lines that are
|
|---|
| 299 | completely empty; they do not affect lines that look empty but contain
|
|---|
| 300 | space or tab characters. With these options, for example, a file
|
|---|
| 301 | containing
|
|---|
| 302 | 1. A point is that which has no part.
|
|---|
| 303 |
|
|---|
| 304 | 2. A line is breadthless length.
|
|---|
| 305 | -- Euclid, The Elements, I
|
|---|
| 306 |
|
|---|
| 307 | is considered identical to a file containing
|
|---|
| 308 | 1. A point is that which has no part.
|
|---|
| 309 | 2. A line is breadthless length.
|
|---|
| 310 |
|
|---|
| 311 |
|
|---|
| 312 | -- Euclid, The Elements, I
|
|---|
| 313 |
|
|---|
| 314 |
|
|---|
| 315 | File: diff.info, Node: Case Folding, Next: Specified Folding, Prev: Blank Lines, Up: Comparison
|
|---|
| 316 |
|
|---|
| 317 | Suppressing Case Differences
|
|---|
| 318 | ============================
|
|---|
| 319 |
|
|---|
| 320 | GNU `diff' can treat lower case letters as equivalent to their upper
|
|---|
| 321 | case counterparts, so that, for example, it considers `Funky Stuff',
|
|---|
| 322 | `funky STUFF', and `fUNKy stuFf' to all be the same. To request this,
|
|---|
| 323 | use the `-i' or `--ignore-case' option.
|
|---|
| 324 |
|
|---|
| 325 |
|
|---|
| 326 | File: diff.info, Node: Specified Folding, Next: Brief, Prev: Case Folding, Up: Comparison
|
|---|
| 327 |
|
|---|
| 328 | Suppressing Lines Matching a Regular Expression
|
|---|
| 329 | ===============================================
|
|---|
| 330 |
|
|---|
| 331 | To ignore insertions and deletions of lines that match a
|
|---|
| 332 | `grep'-style regular expression, use the `-I REGEXP' or
|
|---|
| 333 | `--ignore-matching-lines=REGEXP' option. You should escape regular
|
|---|
| 334 | expressions that contain shell metacharacters to prevent the shell from
|
|---|
| 335 | expanding them. For example, `diff -I '^[[:digit:]]'' ignores all
|
|---|
| 336 | changes to lines beginning with a digit.
|
|---|
| 337 |
|
|---|
| 338 | However, `-I' only ignores the insertion or deletion of lines that
|
|---|
| 339 | contain the regular expression if every changed line in the hunk--every
|
|---|
| 340 | insertion and every deletion--matches the regular expression. In other
|
|---|
| 341 | words, for each nonignorable change, `diff' prints the complete set of
|
|---|
| 342 | changes in its vicinity, including the ignorable ones.
|
|---|
| 343 |
|
|---|
| 344 | You can specify more than one regular expression for lines to ignore
|
|---|
| 345 | by using more than one `-I' option. `diff' tries to match each line
|
|---|
| 346 | against each regular expression.
|
|---|
| 347 |
|
|---|
| 348 |
|
|---|
| 349 | File: diff.info, Node: Brief, Next: Binary, Prev: Specified Folding, Up: Comparison
|
|---|
| 350 |
|
|---|
| 351 | Summarizing Which Files Differ
|
|---|
| 352 | ==============================
|
|---|
| 353 |
|
|---|
| 354 | When you only want to find out whether files are different, and you
|
|---|
| 355 | don't care what the differences are, you can use the summary output
|
|---|
| 356 | format. In this format, instead of showing the differences between the
|
|---|
| 357 | files, `diff' simply reports whether files differ. The `-q' and
|
|---|
| 358 | `--brief' options select this output format.
|
|---|
| 359 |
|
|---|
| 360 | This format is especially useful when comparing the contents of two
|
|---|
| 361 | directories. It is also much faster than doing the normal line by line
|
|---|
| 362 | comparisons, because `diff' can stop analyzing the files as soon as it
|
|---|
| 363 | knows that there are any differences.
|
|---|
| 364 |
|
|---|
| 365 | You can also get a brief indication of whether two files differ by
|
|---|
| 366 | using `cmp'. For files that are identical, `cmp' produces no output.
|
|---|
| 367 | When the files differ, by default, `cmp' outputs the byte and line
|
|---|
| 368 | number where the first difference occurs. You can use the `-s' option
|
|---|
| 369 | to suppress that information, so that `cmp' produces no output and
|
|---|
| 370 | reports whether the files differ using only its exit status (*note
|
|---|
| 371 | Invoking cmp::).
|
|---|
| 372 |
|
|---|
| 373 | Unlike `diff', `cmp' cannot compare directories; it can only compare
|
|---|
| 374 | two files.
|
|---|
| 375 |
|
|---|
| 376 |
|
|---|
| 377 | File: diff.info, Node: Binary, Prev: Brief, Up: Comparison
|
|---|
| 378 |
|
|---|
| 379 | Binary Files and Forcing Text Comparisons
|
|---|
| 380 | =========================================
|
|---|
| 381 |
|
|---|
| 382 | If `diff' thinks that either of the two files it is comparing is
|
|---|
| 383 | binary (a non-text file), it normally treats that pair of files much as
|
|---|
| 384 | if the summary output format had been selected (*note Brief::), and
|
|---|
| 385 | reports only that the binary files are different. This is because line
|
|---|
| 386 | by line comparisons are usually not meaningful for binary files.
|
|---|
| 387 |
|
|---|
| 388 | `diff' determines whether a file is text or binary by checking the
|
|---|
| 389 | first few bytes in the file; the exact number of bytes is system
|
|---|
| 390 | dependent, but it is typically several thousand. If every byte in that
|
|---|
| 391 | part of the file is non-null, `diff' considers the file to be text;
|
|---|
| 392 | otherwise it considers the file to be binary.
|
|---|
| 393 |
|
|---|
| 394 | Sometimes you might want to force `diff' to consider files to be
|
|---|
| 395 | text. For example, you might be comparing text files that contain null
|
|---|
| 396 | characters; `diff' would erroneously decide that those are non-text
|
|---|
| 397 | files. Or you might be comparing documents that are in a format used
|
|---|
| 398 | by a word processing system that uses null characters to indicate
|
|---|
| 399 | special formatting. You can force `diff' to consider all files to be
|
|---|
| 400 | text files, and compare them line by line, by using the `-a' or
|
|---|
| 401 | `--text' option. If the files you compare using this option do not in
|
|---|
| 402 | fact contain text, they will probably contain few newline characters,
|
|---|
| 403 | and the `diff' output will consist of hunks showing differences between
|
|---|
| 404 | long lines of whatever characters the files contain.
|
|---|
| 405 |
|
|---|
| 406 | You can also force `diff' to consider all files to be binary files,
|
|---|
| 407 | and report only whether they differ (but not how). Use the `-q' or
|
|---|
| 408 | `--brief' option for this.
|
|---|
| 409 |
|
|---|
| 410 | Differing binary files are considered to cause trouble because the
|
|---|
| 411 | resulting `diff' output does not capture all the differences. This
|
|---|
| 412 | trouble causes `diff' to exit with status 2. However, this trouble
|
|---|
| 413 | cannot occur with the `--a' or `--text' option, or with the `-q' or
|
|---|
| 414 | `--brief' option, as these options both cause `diff' to treat binary
|
|---|
| 415 | files like text files.
|
|---|
| 416 |
|
|---|
| 417 | In operating systems that distinguish between text and binary files,
|
|---|
| 418 | `diff' normally reads and writes all data as text. Use the `--binary'
|
|---|
| 419 | option to force `diff' to read and write binary data instead. This
|
|---|
| 420 | option has no effect on a POSIX-compliant system like GNU or
|
|---|
| 421 | traditional Unix. However, many personal computer operating systems
|
|---|
| 422 | represent the end of a line with a carriage return followed by a
|
|---|
| 423 | newline. On such systems, `diff' normally ignores these carriage
|
|---|
| 424 | returns on input and generates them at the end of each output line, but
|
|---|
| 425 | with the `--binary' option `diff' treats each carriage return as just
|
|---|
| 426 | another input character, and does not generate a carriage return at the
|
|---|
| 427 | end of each output line. This can be useful when dealing with non-text
|
|---|
| 428 | files that are meant to be interchanged with POSIX-compliant systems.
|
|---|
| 429 |
|
|---|
| 430 | The `--strip-trailing-cr' causes `diff' to treat input lines that
|
|---|
| 431 | end in carriage return followed by newline as if they end in plain
|
|---|
| 432 | newline. This can be useful when comparing text that is imperfectly
|
|---|
| 433 | imported from many personal computer operating systems. This option
|
|---|
| 434 | affects how lines are read, which in turn affects how they are compared
|
|---|
| 435 | and output.
|
|---|
| 436 |
|
|---|
| 437 | If you want to compare two files byte by byte, you can use the `cmp'
|
|---|
| 438 | program with the `-l' option to show the values of each differing byte
|
|---|
| 439 | in the two files. With GNU `cmp', you can also use the `-b' option to
|
|---|
| 440 | show the ASCII representation of those bytes. *Note Invoking cmp::,
|
|---|
| 441 | for more information.
|
|---|
| 442 |
|
|---|
| 443 | If `diff3' thinks that any of the files it is comparing is binary (a
|
|---|
|
|---|