OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / gnumaniak / original / man1 / diff.1
1 .\" You may copy, distribute and modify under the terms of the LDP General
2 .\" Public License as specified in the LICENSE file that comes with the
3 .\" gnumaniak distribution
4 .\"
5 .\" The author kindly requests that no comments regarding the "better"
6 .\" suitability or up-to-date notices of any info documentation alternative
7 .\" is added without contacting him first.
8 .\"
9 .\" (C) 2002 Ragnar Hojland Espinosa <ragnar@ragnar-hojland.com>
10 .\"
11 .\"     GNU diff man page
12 .\"     man pages are NOT obsolete!
13 .\"     <ragnar@ragnar-hojland.com>
14 .TH DIFF 1 "October 2002" "GNU diff Utilities 2.8.1"
15 .SH NAME
16 \fBdiff\fR \- find differences between two files
17 .SH SYNOPSIS
18 .B diff
19 [\fB\-abcdefhilnpqrstuwyBEHNPT\fR]
20 [\-\fILINES\fR]
21 [\fB\-x \fIPATTERN\fR]
22 [\fB\-C \fILINES\fR]
23 [\fB\-D \fINAME\fR]
24 [\fB\-F \fIREGEXP\fR] 
25 [\fB\-I \fIREGEXP\fR]
26 [\fB\-L \fILABEL\fR]
27 [\fB\-S \fIFILE\fR]
28 [\fB\-U \fILINES\fR]
29 [\fB\-W \fICOLUMNS\fR]
30 [\fB\-X \fIFILE\fR]
31 [\fB\-\-binary\fR]
32 [\fB\-\-brief\fR]
33 [\fB\-\-changed\-group\-format=\fIfORMAT\fR]
34 [\fB\-\-context\fR[\fB=\fILINES\fR]]
35 [\fB\-\-diff\-program=\fIPROGRAM\fR]
36 [\fB\-\-ed\fR]
37 [\fB\-\-exclude=\fIPATTERN\fR]
38 [\fB\-\-exclude-from=\fIFILE\fR]
39 [\fB\-\-expand\-tabs\fR]
40 [\fB\-\-forward\-ed\fR]
41 [\fB\-\-from\-file=\fIFILE\fR]
42 [\fB\-\-horizon\-lines=\fILINES\fR]
43 [\fB\-\-ifdef=\fINAME\fR]
44 [\fB\-\-ignore\-all\-space\fR]
45 [\fB\-\-ignore\-blank\-lines\fR]
46 [\fB\-\-ignore\-case\fR]
47 [\fB\-\-ignore\-file\-name\-case\fR]
48 [\fB\-\-ignore\-matching\-lines=\fIREGEXP\fR]
49 [\fB\-\-ignore\-space\-change\fR]
50 [\fB\-\-ignore\-tab\-expansion\fR]
51 [\fB\-\-inhibit\-hunk\-merge\fR]
52 [\fB\-\-initial\-tab]
53 [\fB\-\-label=\fILABEL\fR]
54 [\fB\-\-left\-column\fR]
55 [\fB\-\-line\-format=\fIFORMAT\fR]
56 [\fB\-\-minimal\fR]
57 [\fB\-\-new\-file\fR]
58 [\fB\-\-new\-group\-format=\fIFORMAT\fR]
59 [\fB\-\-new\-line\-format=\fIFORMAT\fR] 
60 [\fB\-\-no\-ignore\-file\-name\-case] 
61 [\fB\-\-old\-group\-format=\fIFORMAT\fR]
62 [\fB\-\-old\-line\-format=\fIFORMAT\fR]
63 [\fB\-\-paginate\fR] [\fB\-\-rcs\fR]
64 [\fB\-\-recursive\fR]
65 [\fB\-\-report\-identical\-files\fR]
66 [\fB\-\-sdiff\-merge\-assist\fR]
67 [\fB\-\-show\-c\-function\fR]
68 [\fB\-\-show\-function\-line=\fIREGEXP\fR]
69 [\fB\-\-side\-by\-side\fR]
70 [\fB\-\-speed\-large\-files\fR]
71 [\fB\-\-starting\-file=\fIFILE\fR]
72 [\fB\-\-strip\-trailing\-cr\fR]
73 [\fB\-\-supress\-common\-lines\fR]
74 [\fB\-\-text\fR] 
75 [\fB\-\-to\-file=\fIFILE\fR]
76 [\fB\-\-unchanged\-group\-format=\fIFORMAT\fR]
77 [\fB\-\-unchanged\-line\-format=\fIFORMAT\fR]
78 [\fB\-\-unidirectional\-new\-file]
79 [\fB\-\-unified\fR[\fB=\fILINES\fR]]
80 [\fB\-\-width=\fICOLUMNS\fR]
81 .I FROMFILE TOFILE
82
83 .B diff
84 [\fB\-v\fR] [\fB\-\-help\fR] [\fB\-\-version\fR]
85
86 .SH DESCRIPTION
87 .B diff
88 compares two files and outputs descriptions of their differences.
89
90 In the simplest case, the files to compare are
91 .I FROMFILE
92 and
93 .IR TOFILE .
94 At most one of these two file names may be
95 .RB ` \- ',
96 which tells
97 .B diff
98 to read the standard input for that file.
99
100 If 
101 .I FROMFILE
102 is a directory and
103 .I TOFILE
104 is not,
105 .B diff
106 compares the file in directory
107 .I FROMFILE
108 whose file name is that of
109 .IR TOFILE ,
110 and vice versa.  The non-directory file must not be
111 .RB ` \- '.
112
113 If both files are directories,
114 .B diff
115 compares corresponding files in both directories, in
116 alphabetical order; this comparison is not recursive unless the
117 .B \-r
118 or
119 .B \-\-recursive
120 option is given.
121 .B diff
122 never compares the actual contents of a directory as if it were a file.  The
123 file that is fully specified may not be
124 .RB ` \- ',
125 , because standard
126 input is nameless and the notion of ``file with the same name'' does not
127 apply.
128
129 If the
130 .B \-\-from\-file=\fIFILE\fR
131 option is given, the number of file names
132 is arbitrary, and \fIFILE\fR is compared to each named file.  Similarly, if
133 the
134 .B \-\-to\-file=\fIFILE\fR
135 option is given, each named file is compared to \fIFILE\fR.
136
137 .SH OPTIONS
138 .TP
139 .BI \- LINES
140 Show
141 .I LINES
142 (an integer) lines of context.  This option does not
143 specify an output format by itself; it has no effect unless it is
144 combined with
145 .B \-c
146 or
147 .BR \-u .
148 This option is obsolete.  For proper
149 operation,
150 .B patch
151 typically needs at least two lines of context.
152 .TP
153 .B \-a, \-\-text
154 Treat all files as text and compare them line-by-line, even if they
155 do not seem to be text.
156 .TP
157 .B \-b, \-\-ignore\-space\-change
158 Ignore changes in amount of white space.  Incomplete lines are ignored.
159 .TP
160 .B \-c
161 Use the context output format.
162 .TP
163 .B \-d, \-\-minimal
164 Change the algorithm to perhaps find a smaller set of changes.  This makes
165 .B diff
166 slower (sometimes much slower).
167 .TP
168 .B \-e, \-\-ed
169 Make output that is a valid
170 .BR ed (1)
171 script.
172 .TP
173 .B \-f, \-\-forward\-ed
174 Make output that looks vaguely like an
175 .B ed
176 script but has changes in the order they appear in the file.
177 .TP
178 .B \-h
179 This option currently has no effect; it is present for Unix
180 compatibility, and has been deprecated.
181 .TP
182 .B \-i, \-\-ignore\-case
183 Ignore changes in case; consider upper- and lower-case letters
184 equivalent.
185 .TP
186 .B \-l, \-\-paginate
187 Pass the output through
188 .BR pr (1)
189 to paginate it.
190 .TP
191 .B \-n, \-\-rcs
192 Output RCS-format diffs; like
193 .B \-f
194 except that each command
195 specifies the number of lines affected.
196 .TP
197 .B \-p, \-\-show\-c\-function
198 Show which C function each change is in. This is equivalent to
199 `\-F'^[_a\-zA\-Z$]''.
200 .TP
201 .B \-q, \-\-brief
202 Report only whether the files differ, not the details of the
203 differences.
204 .TP
205 .B \-r, \-\-recursive
206 When comparing directories, recursively compare any subdirectories
207 found.
208 .TP
209 .B \-s, \-\-report\-identical\-files
210 Report when two files are the same.
211 .TP
212 .B \-t, \-\-expand\-tabs
213 Expand tabs to spaces in the output, to preserve the alignment of tabs
214 in the input files.
215 .TP
216 .B \-u
217 Use the unified output format.
218 .TP
219 .B \-w, \-\-ignore\-all\-space
220 Ignore white space when comparing lines.  Incomplete lines are ignored.
221 .TP
222 .BI "\-x " PATTERN ", \-\-exclude=" PATTERN
223 When comparing directories, ignore files and subdirectories whose basenames
224 match
225 .IR PATTERN .
226 .TP
227 .B \-y, \-\-side\-by\-side
228 Use the side by side output format.
229 .TP
230 .B \-B, \-\-ignore\-blank\-lines
231 Ignore changes that just insert or delete blank lines.
232 .TP
233 .BI "\-C " LINES ", \-\-context[=" LINES ]
234 Use the context output format, showing
235 .I LINES
236 (an integer) lines of
237 context, or three if
238 .I LINES
239 is not given.  For proper operation,
240 .B patch
241 typically needs at least two lines of context.
242 .TP
243 .BI "\-D " NAME ", \-\-ifdef=" NAME
244 Make merged if-then-else format output, conditional on the preprocessor
245 macro
246 .IR NAME .
247 .TP
248 .B "\-E, \-\-ignore\-tab\-expansion"
249 Ignores changes in whitespace due to tab expansion.
250 .TP
251 .BI "\-F " REGEXP ", \-\-show\-function\-line=" REGEXP
252 In context and unified format, for each hunk of differences, show some
253 of the last preceding line that matches
254 .IR REGEXP .
255 .TP
256 .B \-H, \-\-speed\-large\-files
257 Use heuristics to speed handling of large files that have numerous
258 scattered small changes.  \-H short form has been deprecated.
259 .TP
260 .BI "\-I " REGEXP ", \-\-ignore\-matching\-lines=" REGEXP
261 Ignore changes that just insert or delete lines that match
262 .IR REGEXP .
263 .TP
264 .BI "\-L " LABEL ", \-\-label=" LABEL
265 Use
266 .I LABEL
267 instead of the file name in the context format
268 and unified format
269 headers.  \-L short form has been deprecated.
270 .TP
271 .B \-N, \-\-new\-file
272 In directory comparison, if a file is found in only one directory,
273 treat it as present but empty in the other directory.
274 .TP
275 .B \-P, \-\-unidirectional\-new\-file
276 When comparing directories, if a file appears only in the second
277 directory of the two, treat it as present but empty in the other.
278 \-P short form has been deprecated.
279 .TP
280 .BI "\-S " FILE ", \-\-starting\-file=" FILE
281 When comparing directories, start with the file
282 .IR FILE .
283 This is used for resuming an aborted comparison.
284 .TP
285 .B \-T, \-\-initial\-tab
286 Output a tab rather than a space before the text of a line in normal or
287 context format.  This causes the alignment of tabs in the line to look
288 normal.
289 .TP
290 .BI "\-U " LINES ", \-\-unified" \fR[ = LINES \fR]
291 Use the unified output format, showing
292 .I LINES
293 (an integer) lines of context, or three if
294 .I LINES
295 is not given.  For proper operation,
296 .B patch
297 typically needs at least two lines of context.
298 .TP
299 .BI "\-W " COLUMNS ", \-\-width=" COLUMNS
300 Use an output width of
301 .I COLUMNS
302 in side by side format.
303 .TP
304 .BI \-X FILE ", \-\-exclude\-from=" FILE
305 When comparing directories, ignore files and subdirectories whose basenames
306 match any pattern contained in
307 .IR FILE .
308 .TP
309 .B \-\-binary
310 Read and write data in binary mode (no effect in Linux or other POSIX hosts).
311 .TP
312 .BI \-\-changed\-group\-format= FORMAT
313 Use
314 .I FORMAT
315 to output a line group containing differing lines from
316 both files in if-then-else format.
317 .TP
318 .B \-\-diff\-program= \fIPROGRAM
319 Use an external \fIPROGRAM\fR, compatible with \fBdiff\fR, to compare files.
320 .TP
321 .BI \-\-from\-file= FILE
322 Compare \fIFILE\fR with each operand; \fIFILE\fR may be a directory.
323 .TP
324 .BI \-\-horizon\-lines= LINES
325 Do not discard the last
326 .I LINES
327 lines of the common prefix
328 and the first
329 .I LINES
330 lines of the common suffix.
331 .TP
332 .B \-\-ignore\-file\-name\-case
333 Ignore case in filenames when comparing files, so that ``foo'' and ``Foo''
334 are considered the same and therefore compared with each other.
335 .TP
336 .B \-\-inhibit\-hunk\-merge
337 Do not shift hunk boundaries to merge adjacent hunks.
338 .TP
339 .B \-\-left\-column
340 Print only the left column of two common lines in side by side format.
341 .TP
342 .BI \-\-line\-format= FORMAT
343 Use
344 .I FORMAT
345 to output all input lines in in-then-else format.
346 .TP
347 .BI \-\-new\-group\-format= FORMAT
348 Use
349 .I FORMAT
350 to output a group of lines taken from just the second
351 file in if-then-else format.
352 .TP
353 .BI \-\-new\-line\-format= FORMAT
354 Use 
355 .I FORMAT
356 to output a line taken from just the second file in
357 if-then-else format.
358 .TP
359 .B \-\-no\-ignore\-file\-name\-case
360 Case in filenames is taken into account comparing files, so that names ``foo'' and
361 ``Foo'' are not considered the same.  See \fB\-\-ignore\-file\-name\-case\fR.
362 .TP
363 .BI \-\-old\-group\-format= FORMAT
364 Use
365 .I FORMAT
366 to output a group of lines taken from just the first
367 file in if-then-else format.
368 .TP
369 .BI \-\-old\-line\-format= FORMAT
370 Use
371 .I FORMAT
372 to output a line taken from just the first file in
373 if-then-else format.
374 .TP
375 .B \-\-sdiff\-merge\-assist
376 Print extra information to help
377 .BR sdiff (1).
378 .B sdiff
379 uses this option when it runs
380 .BR diff .
381 This option is not intended for users to use directly.
382 .TP
383 .B \-\-strip\-trailing\-cr
384 Strips trailing CRs.  Useful when processing output from systems that use
385 CRLF as end of line markers.
386 .TP
387 .B \-\-suppress\-common\-lines
388 Do not print common lines in side by side format.
389 .TP
390 .BI \-\-unchanged\-group\-format= FORMAT
391 Use
392 .I FORMAT
393 to output a group of common lines taken from both files
394 in if-then-else format.
395 .TP
396 .BI \-\-unchanged\-line\-format= FORMAT
397 Use
398 .I FORMAT
399 to output a line common to both files in if-then-else
400 format.
401 .TP
402 .B "\-\-help"
403 Print a usage message on standard output and exit successfully.
404 .TP
405 .B \-v, \-\-version
406 Output the version number of
407 .BR diff .
408 .SH OUTPUT FORMATS
409 .SS Context format
410 The context output format starts with a two-line header, which looks
411 like this:
412 .sp
413 .nf
414 *** FROMFILE FROMFILE-MODIFICATION-TIME
415 --- TOFILE TOFILE-MODIFICATION-TIME
416 .fi
417 .sp
418 You can change the header's content with the 
419 .BI "-L " LABEL      
420 Next come one or more hunks of differences; each hunk shows
421 one area where the files differ.  Context format hunks look like this:
422 .sp
423 .nf
424 ***************
425 *** FROMFILE-LINE-RANGE ****
426   FROMFILE-LINE
427   FROMFILE-LINE...
428 --- TOFILE-LINE-RANGE ----
429   TOFILE-LINE
430   TOFILE-LINE...
431 .fi
432 .sp
433 The lines of context around the lines that differ start with two
434 space characters.  The lines that differ between the two files start
435 with one of the following indicator characters, followed by a space
436 character:
437 .TP
438 .B !
439 A line that is part of a group of one or more lines that changed
440 between the two files.  There is a corresponding group of lines
441 marked with 
442 .RB ` ! '
443 in the part of this hunk for the other file.
444 .TP
445 .B +
446 An "inserted" line in the second file that corresponds to nothing in the
447 first file.
448 .TP
449 .B -
450 A "deleted" line in the first file that corresponds to nothing in the
451 second file.
452 .PP
453 If all of the changes in a hunk are insertions, the lines of
454 .I FROMFILE
455 are omitted.  If all of the changes are deletions, the lines
456 of 
457 .I TOFILE
458 are omitted.
459 .SS Unified format      
460 The unified output format starts with a two-line header, which looks
461 like this:
462 .sp
463 .nf   
464 --- FROMFILE FROMFILE-MODIFICATION-TIME
465 +++ TOFILE TOFILE-MODIFICATION-TIME
466 .fi
467 .sp
468 You can change the header's content with the 
469 .BI "-L " LABEL      
470 Next come one or more hunks of differences; each hunk shows
471 one area where the files differ.  Unified format hunks look like this:
472 .sp
473 .nf
474 @@ FROMFILE-RANGE TOFILE-RANGE @@
475 LINE-FROM-EITHER-FILE
476 LINE-FROM-EITHER-FILE...
477 .fi
478 .sp
479 The lines lines common to both files start with 1 space character.  The lines
480 that differ start with one of the following indicator characters:
481 .TP
482 .B +
483 A line was added here to the first file.
484 .TP
485 .B -
486 A line was removed here from the first file.
487 .SS Side by side format
488 The files are listed in two columns with a gutter between them.  The
489 gutter contains one of the following markers:
490 .TP
491 .B ` '
492 The corresponding lines are in common.  That is, either the lines
493 are identical, or the difference is ignored because of one of the
494 .B \-\-ignore
495 options.
496 .TP
497 .B |
498 The corresponding lines differ, and they are either both complete
499 or both incomplete.
500 .TP
501 .B <
502 The files differ and only the first file contains the line.
503 .TP
504 .B >
505 The files differ and only the second file contains the line.
506 .TP
507 .B (
508 Only the first file contains the line, but the difference is ignored.
509 .TP
510 .B )
511 Only the second file contains the line, but the difference is ignored.
512 .TP
513 .B \e
514 The corresponding lines differ, and only the first line is incomplete.
515 .TP
516 .B /
517 The corresponding lines differ, and only the second line is incomplete.
518 Normally, an output line is incomplete if and only if the lines that
519 it contains are incomplete.  However, when an output line represents two
520 differing lines, one might be incomplete while the other is not.  In this
521 case, the output line is complete, but its the gutter is marked 
522 .RB ` \e '
523 if the first line is incomplete, 
524 .RB ` / '
525 if the second line is.
526 .PP
527 Side by side format is sometimes easiest to read, but it has
528 limitations.  It generates much wider output than usual, and truncates
529 lines that are too long to fit.  Also, it relies on lining up output
530 more heavily than usual, so its output looks particularly bad if you
531 use varying width fonts, nonstandard tab stops, or nonprinting
532 characters.
533 You can use
534 .BR sdiff (1)
535 command to interactively merge side by side differences.
536 .SS ed(1) format
537 Consists of one or more hunks of differences.  The changes closest to the
538 ends of the files come first so that commands that change the number of
539 lines do not affect how 
540 .B ed
541 interprets line numbers in succeeding commands.
542 .B  ed 
543 format hunks look like this:
544 .sp
545 .nf
546 CHANGE-COMMAND
547 TO-FILE-LINE
548 TO-FILE-LINE...
549 .
550 .fi
551 .sp
552 Because
553 .B ed
554 uses a single period on a line to indicate the end of input, 
555 .B diff
556 protects lines of changes that contain a single period on a line by writing
557 two periods instead, then writing a subsequent ed' command to change the two 
558 periods into one.  The 
559 .B ed
560 format cannot represent an incomplete line, so if the second file ends
561 in a changed incomplete line,
562 .B diff
563 reports an error and then pretends that a newline was appended.
564
565 There are three types of change commands.  Each consists of a line
566 number or comma-separated range of lines in the first file and a single
567 character indicating the kind of change to make.  All line numbers are
568 the original line numbers in the file.  The types of change commands
569 are:
570 .TP
571 .IB L a
572 Add text from the second file after line \fIL\fP in the first file.  For
573 example, `8a' means to add the following lines after line 8 of file 1.
574 .TP
575 .IB R c 
576 Replace the lines in range \fIR\fP in the first file with the following
577 lines.  Like a combined add and delete, but more compact.  For
578 example, `5,7c' means change lines 5-7 of file 1 to read as the
579 text file 2.
580 .TP
581 .IB R d 
582 Delete the lines in range \fIR\fP from the first file.  For example,
583 `5,7d' means delete lines 5-7 of file 1.
584 .PP
585 .B diff
586 can produce output that is like an 
587 .B ed
588 script, but with hunks in forward (front to back) order.  The format of the
589 commands is also changed slightly: command characters precede the lines they
590 modify, spaces separate line numbers in ranges, and no attempt is made
591 to disambiguate hunk lines consisting of a single period.  Like 
592 .B ed
593 format, forward 
594 .B ed 
595 format cannot represent incomplete lines.
596
597 Forward
598 .B ed
599 format is not very useful, because neither
600 .B ed
601 nor
602 .B patch
603 can apply diffs in this format.  It exists mainly for  compatibility with
604 older versions of
605 .BR diff .
606 .SS RCS format
607 The RCS output format is designed specifically for use by the
608 Revision Control System, which is a set of free programs used for
609 organizing different versions and systems of files. It is like the forward
610 .B ed
611 format, but it can represent arbitrary changes to the contents of a file
612 because it avoids the problems with lines consisting of a single period and
613 with incomplete lines.  Instead of ending text sections with a line
614 consisting of a single period, each command specifies the number of
615 lines it affects; a combination of the
616 .RB ` a '
617 and 
618 .RB ` d '
619 commands are used
620 instead of 
621 .RB ` c '.
622 Also, if the second file ends in a changed incomplete line, then the output
623 also ends in an incomplete line.
624 .SH IF\-THEN\-ELSE
625 .SS C source format
626 You can use 
627 .B diff
628 to merge two files of C source code.  The output in this format contains all
629 the lines of both files.  Lines common to both files are output just once;
630 the differing parts are separated by the C preprocessor directives 
631 .BI "#ifdef " NAME
632 or
633 .B #ifndef 
634 .IR NAME ,
635 ,BR #else ", and " #endif .
636 When compiling the output, you select which version to use by either
637 defining or leaving undefined the macro
638 .IR NAME .
639
640 For example, if you change an instance of `wait (&s)' to `waitpid
641 (-1, &s, 0)' and then merge the old and new files with the
642 `\fB--ifdef=\fIHAVE_WAITPID\fR' option, then the affected part of your code 
643 might look like this:
644 .sp
645 .nf
646     do {
647  #ifndef HAVE_WAITPID
648           if ((w = wait (&s)) < 0 && errno != EINTR)
649  #else /* HAVE_WAITPID */
650           if ((w = waitpid (-1, &s, 0)) < 0  &&  errno != EINTR)
651  #endif /* HAVE_WAITPID */
652           return w;
653     } while (w != child);
654 .fi
655 .SS Group formats
656 Line group formats let you specify formats suitable for many
657 applications that allow if-then-else input, including programming
658 languages and text formatting languages.  A line group format specifies
659 the output format for a contiguous group of similar lines.
660
661 For example, the following command compares the TeX files `old' and
662 `new', and outputs a merged file in which old regions are surrounded by
663 `\ebegin{em}'-`\eend{em}' lines, and new regions are surrounded by
664 `\ebegin{bf}'-`\eend{bf}' lines.
665 .sp
666 .nf
667  diff \e
668     --old-group-format='\ebegin{em}
669  %<\eend{em}
670  '  \e
671     --new-group-format='\ebegin{bf}
672  %>\eend{bf}
673  '  \e
674     old new
675 .fi
676 .sp                                                    
677 The following command is equivalent to the above example, but it is a
678 little more verbose, because it spells out the default line group formats.
679 .sp
680 .nf
681  diff \e
682     --old-group-format='\ebegin{em}
683  %<\eend{em}
684  ' \e
685     --new-group-format='\ebegin{bf}
686  %>\eend{bf}
687  ' \e
688     --unchanged-group-format='%=' \e
689     --changed-group-format='\ebegin{em}
690  %<\eend{em}
691  \ebegin{bf}
692  %>\eend{bf}
693  '  \e
694     old new
695 .fi
696 .sp
697 Here is a more advanced example, which outputs a diff listing with headers
698 containing line numbers in a "plain English" style. 
699 .sp
700 .nf
701  diff \e
702     --unchanged-group-format='' \e
703     --old-group-format='-------- %dn line%(n=1?:s) deleted at %df:
704  %<' \e
705     --new-group-format='-------- %dN line%(N=1?:s) added after %de:
706  %>' \e
707     --changed-group-format='-------- %dn line%(n=1?:s) changed at %df:
708  %<-------- to:
709  %>' \e
710     old new
711 .fi
712 .sp
713 To specify a line group format, use \fBdiff\fR with one of the options listed
714 below.  You can specify up to four line group formats, one for each kind of
715 line group.  You should quote \fIFORMAT\fR, because it typically contains
716 shell metacharacters.
717 .TP
718 .BI \-\-old-group\-format= FORMAT
719 These line groups are hunks containing only lines from the first file.  The 
720 default old group format is the same as the changed group format if it is
721 specified; otherwise it is a format that outputs the line group as-is.
722 .TP
723 .BI \-\-new-group\-format= FORMAT
724 These line groups are hunks containing only lines
725 from the second file.  The default new group format is same as the the changed
726 group format if it is specified; otherwise it is a format that outputs the line
727 group as-is.
728 .TP
729 .BI \-\-changed\-group\-format= FORMAT
730 These line groups are hunks containing lines from both files.  The default
731 changed group format is the concatenation of the old and new group formats.
732 .TP
733 .BI \-\-unchanged\-group\-format= FORMAT
734 These line groups contain lines common to both files.  The default unchanged
735 group format is a format that outputs the line group as-is.
736 .SS Group conversions
737 .TP
738 .B %<
739 stands for the lines from the first file, including the trailing
740 newline.  Each line is formatted according to the old line format
741 .TP
742 .B %>
743 stands for the lines from the second file, including the trailing
744 newline.  Each line is formatted according to the new line format.
745 .TP
746 .B %=
747 stands for the lines common to both files, including the trailing
748 newline.  Each line is formatted according to the unchanged line format.
749 .TP
750 .B %%
751 stands for `%'.
752 .TP
753 .B %c'\fIC\fB''
754 where 
755 .I C
756 is a single character, stands for
757 .IR C ".  " C
758 may not be a backslash or an apostrophe.  For example, `%c':'' stands for a
759 colon, even inside the then-part of an if-then-else format, which a colon
760 would normally terminate.
761 .TP
762 .B %c'\eO''
763 where
764 .I O
765 is a string of 1, 2, or 3 octal digits, stands for the
766 character with octal code
767 .IR O .
768 For example, %c'\e0'' stands for a null character.
769 .TP
770 .BI ( A = B ? T : E )
771 If 
772 .I A
773 equals
774 .I B
775 then
776 .I T
777 else
778 .IR E .
779 .I A
780 and
781 .I B
782 are each either a decimal constant or a single letter interpreted as above.
783 This format spec is equivalent to 
784 .IR T " if " A "'s value equals " B "'s; otherwise it is equivalent to " E .
785
786 For example, `%(N=0?no:%dN) line%(N=1?:s)' is equivalent to no
787 lines' if N (the number of lines in the group in the the new file)
788 is 0, to 1 line' if N is 1, and to %dN lines' otherwise.
789 .TP
790 .I FN
791 where F is a 
792 .BR printf (3)
793 conversion specification and 
794 .I N
795 is one of the following letters, stands for 
796 .IR N "'s value formatted with " F .
797 .RS
798 .TP
799 .B e
800 The line number of the line just before the group in the old file.
801 .TP
802 .B f
803 The line number of the first line in the group in the old file; equals E + 1.
804 .TP
805 .B l
806 The line number of the last line in the group in the old file.
807 .TP
808 .B m
809 The line number of the line just after the group in the old file; equals L + 1.
810 .TP
811 .B n
812 The number of lines in the group in the old file; equals L - F + 1.
813 .TP
814 .B E, F, L, M, N
815 Likewise, for lines in the new file.
816 .RE
817 .sp
818 The 
819 .B printf
820 conversion specification can be 
821 .BR %d ", " %o ", " %x ", or " %X ,
822 specifying decimal, octal, lower case hexadecimal, or upper
823 case hexadecimal output respectively.  After the 
824 .RB ` % '
825 the following options can appear in sequence: a 
826 .RB ` - '
827 specifying left-justification; an integer specifying the minimum field width;
828 and a period followed by an optional integer specifying the
829 minimum number of digits.  For example, `%5dN' prints the number
830 of new lines in the group in a field of width 5 characters, using the 
831 .B printf
832 format "%5d"'.
833 .SS Line group format
834 Line formats control how each line taken from an input file is
835 output as part of a line group in if-then-else format.
836    
837 For example, the following command outputs text with a one-column
838 change indicator to the left of the text.  The first column of output
839 is `-' for deleted lines, `|' for added lines, and a space for
840 unchanged lines.  The formats contain newline characters where newlines
841 are desired on output.
842       
843  diff \e
844     --old-line-format='-%l
845  ' \e
846     --new-line-format='|%l
847  ' \e
848     --unchanged-line-format=' %l
849  ' \e
850    old new
851
852 To specify a line format, use one of the following options.  You
853 should quote \fIFORMAT\fR, since it often contains shell metacharacters.
854 .TP
855 .BI \-\-old-line-format= FORMAT
856 Formats lines just from the first file.
857 .TP
858 .BI \-\-new\-line\-format= FORMAT
859 Formats lines just from the second file.
860 .TP
861 .BI \-\-unchanged\-line\-format= FORMAT
862 Formats lines common to both files.
863 .TP
864 .BI \-\-line\-format= FORMAT
865 Formats all lines; in effect, it sets all three above options simultaneously.
866 .PP
867 In a line format, ordinary characters represent themselves; conversion
868 specifications start with
869 .RB ` % '
870 and have  forms.
871 .TP
872 .B %l
873 stands for the the contents of the line, not counting its trailing
874 newline (if any).  This format ignores whether the line is incomplete.
875 .TP
876 .B %L
877 stands for the the contents of the line, including its trailing newline (if
878 any).  If a line is incomplete, this format preserves its incompleteness.
879 .TP
880 .B %%
881 stands for `%'.
882 .TP
883 .B %c'\fIC\fB''
884 where 
885 .I C
886 is a single character, stands for
887 .IR C ".  " C
888 may not be a backslash or an apostrophe.  For example, `%c':'' stands for a
889 colon.
890 .TP
891 .B %c'\eO''
892 where
893 .I O
894 is a string of 1, 2, or 3 octal digits, stands for the
895 character with octal code
896 .IR O .
897 For example, %c'\e0'' stands for a null character.
898 .TP
899 .I Fn
900 where 
901 .I F
902 is a 
903 .B printf conversion specification, stands for the line number formatted with
904 .IR F .
905 For example, `%.5dn' prints the line number using the format `%.5d'.  For
906 more on printf conversion specifications, read the Group Format subsection
907 above. 
908 .PP
909 The default line format is 
910 .RB ` %l '
911 followed by a newline character.  If the input contains tab characters and
912 it is important that they line up on output, you should ensure that `%l' or
913 %L' in a line format is just after a tab stop (e.g. by preceding %l' or %L'
914 with a tab character), or you should use the \fB\-t\fR option.
915
916 Taken together, the line and line group formats let you specify many
917 different formats.  For example, the following command uses a format
918 similar to diff's normal format.  You can tailor this command to get
919 fine control over diff's output.
920 .sp
921 .nf
922  diff \e
923     --old-line-format='< %l
924  ' \e
925     --new-line-format='> %l
926  ' \e
927     --old-group-format='%df%(f=l?:,%dl)d%dE
928  %<' \e
929     --new-group-format='%dea%dF%(F=L?:,%dL)
930  %>' \e
931     --changed-group-format='%df%(f=l?:,%dl)c%dF%(F=L?:,%dL)
932  %<---
933  %>' \e
934     --unchanged-group-format='' \e
935     old new
936 .fi
937 .SH COMPARING DIRECTORIES
938 When both file name arguments to \fBdiff\fR are directories, it compares
939 each file that is contained in both directories, examining file names in
940 alphabetical order.  Normally it is silent about pairs of files that contain
941 no differences, but if you use the \fB\-s\fR option, it reports pairs of 
942 identical files.  Normally \fBdiff\fR reports subdirectories common to both
943 directories without comparing subdirectories' files, but if you use the 
944 \fB\-r\fR option, it compares every corresponding pair of files in the
945 directory trees, as many levels deep as they go.
946
947 For file names that are in only one of the directories, \fBdiff\fR
948 normally does not show the contents of the file that exists; it reports
949 only that the file exists in that directory and not in the other.  You
950 can make \fBdiff\fR act as though the file existed but was empty in the
951 other directory, so that it outputs the entire contents of the file that
952 actually exists.  (It is output as either an insertion or a deletion,
953 depending on whether it is in the first or the second directory given.)
954 To do this, use the \fB\-N\fR option.
955
956 If the older directory contains one or more large files that are not
957 in the newer directory, you can make the patch smaller by using the
958 .B \-P
959 option instead of 
960 .BR \-N .
961 This option is like 
962 .B \-N
963 except that it only inserts the contents of files that appear in the second
964 directory but not the first (that is, files that were added).  At the top of
965 the patch, write instructions for the user applying the patch to remove the
966 files that were deleted before applying the patch.  
967
968 To ignore some files while comparing directories, use the 
969 \fB\-x \fIPATTERN\fR option.  Unlike in the shell, a period at the start of
970 the base of a file name matches a wildcard at the start of a pattern.  You
971 should enclose \fIPATTERN\fR in quotes so that the shell does not expand it.
972 For example, the option `\-x '*.[ao]'' ignores any file whose name ends with
973 `.a' or `.o'. This option accumulates if you specify it more than once.  For
974 example, using the options `-x 'RCS' -x '*,v'' ignores any file or
975 subdirectory whose base name is `RCS' or ends with `,v'.
976 .SH DIAGNOSTICS
977 .B diff
978 exits with one of the following values:
979 .TP
980 .B 0
981 No differences were found.
982 .TP
983 .B 1
984 Some difference was found.
985 .TP
986 .B 2
987 Some error occurred.
988 .SH SEE ALSO
989 cmp(1), comm(1), diff3(1), ed(1), patch(1), pr(1), sdiff(1).
990 .SH NOTES
991 Report bugs to bug-gnu-utils@gnu.org.
992 Page updated by Ragnar Hojland Espinosa <ragnar@ragnar-hojland.com>