⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 diff.texi

📁 这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易于我们学习和理解
💻 TEXI
📖 第 1 页 / 共 5 页
字号:
The default old group format is the same as the changed group format ifit is specified; otherwise it is a format that outputs the line group as-is.@item --new-group-format=@var{format}These line groups are hunks containing only lines from the secondfile.  The default new group format is same as the the changed groupformat if it is specified; otherwise it is a format that outputs theline group as-is.@item --changed-group-format=@var{format}These line groups are hunks containing lines from both files.  Thedefault changed group format is the concatenation of the old and newgroup formats.@item --unchanged-group-format=@var{format}These line groups contain lines common to both files.  The defaultunchanged group format is a format that outputs the line group as-is.@end tableIn a line group format, ordinary characters represent themselves;conversion specifications start with @samp{%} and have one of thefollowing forms.@table @samp@item %<stands for the lines from the first file, including the trailing newline.Each line is formatted according to the old line format (@pxref{Line Formats}).@item %>stands for the lines from the second file, including the trailing newline.Each line is formatted according to the new line format.@item %=stands for the lines common to both files, including the trailing newline.Each line is formatted according to the unchanged line format.@item %%stands for @samp{%}.@item %c'@var{C}'where @var{C} is a single character, stands for @var{C}.@var{C} may not be a backslash or an apostrophe.For example, @samp{%c':'} stands for a colon, even insidethe then-part of an if-then-else format, which a colon wouldnormally terminate.@item %c'\@var{O}'where @var{O} is a string of 1, 2, or 3 octal digits,stands for the character with octal code @var{O}.For example, @samp{%c'\0'} stands for a null character.@item @var{F}@var{n}where @var{F} is a @code{printf} conversion specification and @var{n} is oneof the following letters, stands for @var{n}'s value formatted with @var{F}.@table @samp@item eThe line number of the line just before the group in the old file.@item fThe line number of the first line in the group in the old file;equals @var{e} + 1.@item lThe line number of the last line in the group in the old file.@item mThe line number of the line just after the group in the old file;equals @var{l} + 1.@item nThe number of lines in the group in the old file; equals @var{l} - @var{f} + 1.@item E, F, L, M, NLikewise, for lines in the new file.@end tableThe @code{printf} conversion specification can be @samp{%d},@samp{%o}, @samp{%x}, or @samp{%X}, specifying decimal, octal,lower case hexadecimal, or upper case hexadecimal outputrespectively.  After the @samp{%} the following options can appear insequence: a @samp{-} specifying left-justification; an integerspecifying the minimum field width; and a period followed by anoptional integer specifying the minimum number of digits.For example, @samp{%5dN} prints the number of new lines in the groupin a field of width 5 characters, using the @code{printf} format @code{"%5d"}.@item (@var{A}=@var{B}?@var{T}:@var{E})If @var{A} equals @var{B} then @var{T} else @var{E}.@var{A} and @var{B} are each either a decimal constantor a single letter interpreted as above.This format spec is equivalent to @var{T} if@var{A}'s value equals @var{B}'s; otherwise it is equivalent to @var{E}.For example, @samp{%(N=0?no:%dN) line%(N=1?:s)} is equivalent to@samp{no lines} if @var{N} (the number of lines in the group in the thenew file) is 0, to @samp{1 line} if @var{N} is 1, and to @samp{%dN lines}otherwise.@end table@node Line Formats, Detailed If-then-else, Line Group Formats, If-then-else@subsection Line Formats@cindex line formatsLine formats control how each line taken from an input file isoutput as part of a line group in if-then-else format.For example, the following command outputs text with a one-columnchange indicator to the left of the text.  The first column of outputis @samp{-} for deleted lines, @samp{|} for added lines, and a spacefor unchanged lines.  The formats contain newline characters wherenewlines are desired on output.@examplediff \   --old-line-format='-%l' \   --new-line-format='|%l' \   --unchanged-line-format=' %l' \   old new@end exampleTo specify a line format, use one of the following options.  You shouldquote @var{format}, since it often contains shell metacharacters.@table @samp@item --old-line-format=@var{format}formats lines just from the first file.@item --new-line-format=@var{format}formats lines just from the second file.@item --unchanged-line-format=@var{format}formats lines common to both files.@item --line-format=@var{format}formats all lines; in effect, it sets all three above options simultaneously.@end tableIn a line format, ordinary characters represent themselves;conversion specifications start with @samp{%} and have one of thefollowing forms.@table @samp@item %lstands for the the contents of the line, not counting its trailingnewline (if any).  This format ignores whether the line is incomplete;@xref{Incomplete Lines}.@item %Lstands for the the contents of the line, including its trailing newline(if any).  If a line is incomplete, this format preserves itsincompleteness.@item %%stands for @samp{%}.@item %c'@var{C}'where @var{C} is a single character, stands for @var{C}.@var{C} may not be a backslash or an apostrophe.For example, @samp{%c':'} stands for a colon.@item %c'\@var{O}'where @var{O} is a string of 1, 2, or 3 octal digits,stands for the character with octal code @var{O}.For example, @samp{%c'\0'} stands for a null character.@item @var{F}nwhere @var{F} is a @code{printf} conversion specification,stands for the line number formatted with @var{F}.For example, @samp{%.5dn} prints the line number using the@code{printf} format @code{"%.5d"}.  @xref{Line Group Formats}, formore about printf conversion specifications.@end tableThe default line format is @samp{%l} followed by a newline character.If the input contains tab characters and it is important that they lineup on output, you should ensure that @samp{%l} or @samp{%L} in a lineformat is just after a tab stop (e.g.@: by preceding @samp{%l} or@samp{%L} with a tab character), or you should use the @samp{-t} or@samp{--expand-tabs} option.Taken together, the line and line group formats let you specify manydifferent formats.  For example, the following command uses a formatsimilar to @code{diff}'s normal format.  You can tailor this commandto get fine control over @code{diff}'s output.@examplediff \   --old-line-format='< %l' \   --new-line-format='> %l' \   --old-group-format='%df%(f=l?:,%dl)d%dE%<' \   --new-group-format='%dea%dF%(F=L?:,%dL)%>' \   --changed-group-format='%df%(f=l?:,%dl)c%dF%(F=L?:,%dL)%<---%>' \   --unchanged-group-format='' \   old new@end example@node Detailed If-then-else, Example If-then-else, Line Formats, If-then-else@subsection Detailed Description of If-then-else FormatFor lines common to both files, @code{diff} uses the unchanged linegroup format.  For each hunk of differences in the merged outputformat, if the hunk contains only lines from the first file,@code{diff} uses the old line group format; if the hunk contains onlylines from the second file, @code{diff} uses the new group format;otherwise, @code{diff} uses the changed group format.The old, new, and unchanged line formats specify the output format oflines from the first file, lines from the second file, and lines commonto both files, respectively.The option @samp{--ifdef=@var{name}} is equivalent tothe following sequence of options using shell syntax:@example--old-group-format='#ifndef @var{name}%<#endif /* not @var{name} */' \--new-group-format='#ifdef @var{name}%>#endif /* @var{name} */' \--unchanged-group-format='%=' \--changed-group-format='#ifndef @var{name}%<#else /* @var{name} */%>#endif /* @var{name} */'@end exampleYou should carefully check the @code{diff} output for proper nesting.For example, when using the the @samp{-D @var{name}} or@samp{--ifdef=@var{name}} option, you should check that if thediffering lines contain any of the C preprocessor directives@samp{#ifdef}, @samp{#ifndef}, @samp{#else}, @samp{#elif}, or@samp{#endif}, they are nested properly and match.  If they don't, youmust make corrections manually.  It is a good idea to carefully checkthe resulting code anyway to make sure that it really does what youwant it to; depending on how the input files were produced, the outputmight contain duplicate or otherwise incorrect code.The @code{patch} @samp{-D @var{name}} option behaves just likethe @code{diff} @samp{-D @var{name}} option, except it operates ona file and a diff to produce a merged file; @xref{patch Options}.@node Example If-then-else, , Detailed If-then-else, If-then-else@subsection An Example of If-then-else FormatHere is the output of @samp{diff -DTWO lao tzu} (@pxref{Samplediff Input}, for the complete contents of the two files):@example#ifndef TWOThe Way that can be told of is not the eternal Way;The name that can be named is not the eternal name.#endif /* not TWO */The Nameless is the origin of Heaven and Earth;#ifndef TWOThe Named is the mother of all things.#else /* TWO */The named is the mother of all things.#endif /* TWO */Therefore let there always be non-being,  so we may see their subtlety,And let there always be being,  so we may see their outcome.The two are the same,But after they are produced,  they have different names.#ifdef TWOThey both may be called deep and profound.Deeper and more profound,The door of all subtleties!#endif /* TWO */@end example@node Comparing Directories, Adjusting Output, Output Formats, Top@chapter Comparing DirectoriesYou can use @code{diff} to compare some or all of the files in twodirectory trees.  When both file name arguments to @code{diff} aredirectories, it compares each file that is contained in bothdirectories, examining file names in alphabetical order.  Normally@code{diff} is silent about pairs of files that contain no differences,but if you use the @samp{-s} or @samp{--report-identical-files} option,it reports pairs of identical files.  Normally @code{diff} reportssubdirectories common to both directories without comparingsubdirectories' files, but if you use the @samp{-r} or@samp{--recursive} option, it compares every corresponding pair of filesin the directory trees, as many levels deep as they go.For file names that are in only one of the directories, @code{diff}normally does not show the contents of the file that exists; it reportsonly that the file exists in that directory and not in the other.  Youcan make @code{diff} act as though the file existed but was empty in theother directory, so that it outputs the entire contents of the file thatactually exists.  (It is output as either an insertion or adeletion, depending on whether it is in the first or the seconddirectory given.)  To do this, use the @samp{-N} or @samp{--new-file}option.If the older directory contains one or more large files that are not inthe newer directory, you can make the patch smaller by using the@samp{-P} or @samp{--unidirectional-new-file} option instead of @samp{-N}.This option is like @samp{-N} except that it only inserts the contentsof files that appear in the second directory but not the first (that is,files that were added).  At the top of the patch, write instructions forthe user applying the patch to remove the files that were deleted beforeapplying the patch.  @xref{Making Patches}, for more discussion ofmaking patches for distribution.To ignore some files while comparing directories, use the @samp{-x@var{pattern}} or @samp{--exclude=@var{pattern}} option.  This optionignores any files or subdirectories whose base names match the shellpattern @var{pattern}.  Unlike in the shell, a period at the start ofthe base of a file name matches a wildcard at the start of a pattern.You should enclose @var{pattern} in quotes so that the shell does notexpand it.  For example, the option @samp{-x '*.[ao]'} ignores any filewhose name ends with @samp{.a} or @samp{.o}.This option accumulates if you specify 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -