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

📄 diff.html

📁 posix标准英文,html格式
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<pre><tt>"*** %s %s\n",</tt> <i>file1</i><tt>, &lt;</tt><i>file1 timestamp</i><tt>&gt;"--- %s %s\n",</tt> <i>file2</i><tt>, &lt;</tt><i>file2 timestamp</i><tt>&gt;</tt></pre><p>Each &lt;<i>file</i>&gt; field shall be the pathname of the corresponding file being compared. The pathname written for standardinput is unspecified.</p><p>In the POSIX locale, each &lt;<i>timestamp</i>&gt; field shall be equivalent to the output from the following command:</p><pre><tt>date "+%a %b %e %T %Y"</tt></pre><p>without the trailing &lt;newline&gt;, executed at the time of last modification of the corresponding file (or the current time,if the file is standard input).</p><p>Then, the following output formats shall be applied for every set of changes.</p><p>First, a line shall be written in the following format:</p><pre><tt>"***************\n"</tt></pre><p>Next, the range of lines in <i>file1</i> shall be written in the following format if the range contains two or more lines:</p><pre><tt>"*** %d,%d ****\n", &lt;</tt><i>beginning line number</i><tt>&gt;, &lt;</tt><i>ending line number</i><tt>&gt;</tt></pre><p>and the following format otherwise:</p><pre><tt>"*** %d ****\n", &lt;</tt><i>ending line number</i><tt>&gt;</tt></pre><p>The ending line number of an empty range shall be the number of the preceding line, or 0 if the range is at the start of thefile.</p><p>Next, the affected lines along with lines of context (unaffected lines) shall be written. Unaffected lines shall be written inthe following format:</p><pre><tt>"<img src="../images/delta.gif" border="0"><img src="../images/delta.gif" border="0">%s", &lt;</tt><i>unaffected_line</i><tt>&gt;</tt></pre><p>Deleted lines shall be written as:</p><pre><tt>"-<img src="../images/delta.gif" border="0">%s", &lt;</tt><i>deleted_line</i><tt>&gt;</tt></pre><p>Changed lines shall be written as:</p><pre><tt>"!<img src="../images/delta.gif" border="0">%s", &lt;</tt><i>changed_line</i><tt>&gt;</tt></pre><p>Next, the range of lines in <i>file2</i> shall be written in the following format if the range contains two or more lines:</p><pre><tt>"--- %d,%d ----\n", &lt;</tt><i>beginning line number</i><tt>&gt;, &lt;</tt><i>ending line number</i><tt>&gt;</tt></pre><p>and the following format otherwise:</p><pre><tt>"--- %d ----\n", &lt;</tt><i>ending line number</i><tt>&gt;</tt></pre><p>Then, lines of context and changed lines shall be written as described in the previous formats. Lines added from <i>file2</i>shall be written in the following format:</p><pre><tt>"+<img src="../images/delta.gif" border="0">%s", &lt;</tt><i>added_line</i><tt>&gt;</tt></pre></blockquote><h4><a name="tag_04_37_11"></a>STDERR</h4><blockquote><p>The standard error shall be used only for diagnostic messages.</p></blockquote><h4><a name="tag_04_37_12"></a>OUTPUT FILES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_04_37_13"></a>EXTENDED DESCRIPTION</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_04_37_14"></a>EXIT STATUS</h4><blockquote><p>The following exit values shall be returned:</p><dl compact><dt>&nbsp;0</dt><dd>No differences were found.</dd><dt>&nbsp;1</dt><dd>Differences were found.</dd><dt>&gt;1</dt><dd>An error occurred.</dd></dl></blockquote><h4><a name="tag_04_37_15"></a>CONSEQUENCES OF ERRORS</h4><blockquote><p>Default.</p></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_04_37_16"></a>APPLICATION USAGE</h4><blockquote><p>If lines at the end of a file are changed and other lines are added, <i>diff</i> output may show this as a delete and add, as achange, or as a change and add; <i>diff</i> is not expected to know which happened and users should not care about the differencein output as long as it clearly shows the differences between the files.</p></blockquote><h4><a name="tag_04_37_17"></a>EXAMPLES</h4><blockquote><p>If <b>dir1</b> is a directory containing a directory named <b>x</b>, <b>dir2</b> is a directory containing a directory named<b>x</b>, <b>dir1/x</b> and <b>dir2/x</b> both contain files named <b>date.out</b>, and <b>dir2/x</b> contains a file named<b>y</b>, the command:</p><pre><tt>diff -r dir1 dir2</tt></pre><p>could produce output similar to:</p><pre><tt>Common subdirectories: dir1/x and dir2/xOnly in dir2/x: ydiff -r dir1/x/date.out dir2/x/date.out1c1&lt; Mon Jul  2 13:12:16 PDT 1990---&gt; Tue Jun 19 21:41:39 PDT 1990</tt></pre></blockquote><h4><a name="tag_04_37_18"></a>RATIONALE</h4><blockquote><p>The <b>-h</b> option was omitted because it was insufficiently specified and does not add to applications portability.</p><p>Historical implementations employ algorithms that do not always produce a minimum list of differences; the current languageabout making every effort is the best this volume of IEEE&nbsp;Std&nbsp;1003.1-2001 can do, as there is no metric that could beemployed to judge the quality of implementations against any and all file contents. The statement &quot;This list should be minimal''clearly implies that implementations are not expected to provide the following output when comparing two 100-line files that differin only one character on a single line:</p><pre><tt>1,100c1,100all 100 lines from file1 preceded with "&lt; "---all 100 lines from file2 preceded with "&gt; "</tt></pre><p>The &quot;Only in&quot; messages required when the <b>-r</b> option is specified are not used by most historical implementations if the<b>-e</b> option is also specified. It is required here because it provides useful information that must be provided to update atarget directory hierarchy to match a source hierarchy. The &quot;Common subdirectories&quot; messages are written by System V and 4.3 BSDwhen the <b>-r</b> option is specified. They are allowed here but are not required because they are reporting on something that isthe same, not reporting a difference, and are not needed to update a target hierarchy.</p><p>The <b>-c</b> option, which writes output in a format using lines of context, has been included. The format is useful for avariety of reasons, among them being much improved readability and the ability to understand difference changes when the targetfile has line numbers that differ from another similar, but slightly different, copy. The <a href="../utilities/patch.html"><i>patch</i></a> utility is most valuable when working with difference listings using the context format.The BSD version of <b>-c</b> takes an optional argument specifying the amount of context. Rather than overloading <b>-c</b> andbreaking the Utility Syntax Guidelines for <i>diff</i>, the standard developers decided to add a separate option for specifying acontext diff with a specified amount of context ( <b>-C</b>). Also, the format for context <i>diff</i>s was extended slightly in4.3 BSD to allow multiple changes that are within context lines from each other to be merged together. The output format containsan additional four asterisks after the range of affected lines in the first filename. This was to provide a flag for old programs(like old versions of <a href="../utilities/patch.html"><i>patch</i></a>) that only understand the old context format. The versionof context described here does not require that multiple changes within context lines be merged, but it does not prohibit iteither. The extension is upwards-compatible, so any vendors that wish to retain the old version of <i>diff</i> can do so by addingthe extra four asterisks (that is, utilities that currently use <i>diff</i> and understand the new merged format will alsounderstand the old unmerged format, but not <i>vice versa</i>).</p><p>The substitute command was added as an additional format for the <b>-e</b> option. This was added to provide implementationswith a way to fix the classic &quot;dot alone on a line&quot; bug present in many versions of <i>diff</i>. Since many implementations havefixed this bug, the standard developers decided not to standardize broken behavior, but rather to provide the necessary tool forfixing the bug. One way to fix this bug is to output two periods whenever a lone period is needed, then terminate the appendcommand with a period, and then use the substitute command to convert the two periods into one period.</p><p>The BSD-derived <b>-r</b> option was added to provide a mechanism for using <i>diff</i> to compare two file system trees. Thisbehavior is useful, is standard practice on all BSD-derived systems, and is not easily reproducible with the <a href="../utilities/find.html"><i>find</i></a> utility.</p><p>The requirement that <i>diff</i> not compare files in some circumstances, even though they have the same name, is based on theactual output of historical implementations. The message specified here is already in use when a directory is being compared to anon-directory. It is extended here to preclude the problems arising from running into FIFOs and other files that would cause<i>diff</i> to hang waiting for input with no indication to the user that <i>diff</i> was hung. In most common usage, <i>diff</i><b>-r</b> should indicate differences in the file hierarchies, not the difference of contents of devices pointed to by thehierarchies.</p><p>Many early implementations of <i>diff</i> require seekable files. Since the System Interfaces volume ofIEEE&nbsp;Std&nbsp;1003.1-2001 supports named pipes, the standard developers decided that such a restriction was unreasonable. Notealso that the allowed filename <b>-</b> almost always refers to a pipe.</p><p>No directory search order is specified for <i>diff</i>. The historical ordering is, in fact, not optimal, in that it prints outall of the differences at the current level, including the statements about all common subdirectories before recursing into thosesubdirectories.</p><p>The message:</p><pre><tt>"diff %s %s %s\n", &lt;</tt><i>diff_options</i><tt>&gt;, &lt;</tt><i>filename1</i><tt>&gt;, &lt;</tt><i>filename2</i><tt>&gt;</tt></pre><p>does not vary by locale because it is the representation of a command, not an English sentence.</p></blockquote><h4><a name="tag_04_37_19"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_04_37_20"></a>SEE ALSO</h4><blockquote><p><a href="cmp.html"><i>cmp</i></a>, <a href="comm.html"><i>comm</i></a>, <a href="ed.html"><i>ed</i></a>, <a href="find.html"><i>find</i></a></p></blockquote><h4><a name="tag_04_37_21"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 2.</p></blockquote><h4><a name="tag_04_37_22"></a>Issue 5</h4><blockquote><p>The FUTURE DIRECTIONS section is added.</p></blockquote><h4><a name="tag_04_37_23"></a>Issue 6</h4><blockquote><p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p><ul><li><p>The <b>-f</b> option is added.</p></li></ul><p>The output format for <b>-c</b> or <b>-C</b> format is changed to align with changes to the IEEE&nbsp;P1003.2b draft standardresulting from IEEE PASC Interpretation 1003.2 #71.</p><p>The normative text is reworded to avoid use of the term &quot;must&quot; for application requirements.</p><p>IEEE&nbsp;Std 1003.1-2001/Cor&nbsp;1-2002, item XCU/TC1/D6/20 is applied, changing the STDOUT section. This changes thespecification of <i>diff</i> <b>-c</b> so that it agrees with existing practice when contexts contain zero lines or one line.</p></blockquote><div class="box"><em>End of informative text.</em></div><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX &reg; is a registered Trademark of The Open Group.<br>POSIX &reg; is a registered Trademark of The IEEE.<br>[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>]</font></center><!--footer end--><hr size="2" noshade></body></html>

⌨️ 快捷键说明

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