📄 diff.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>diff</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_001_014_415"> </a>NAME</h4><blockquote>diff - compare two files</blockquote><h4><a name = "tag_001_014_416"> </a>SYNOPSIS</h4><blockquote><pre><code>diff <b>[</b>-c| -e| -f| -C <i>n</i><b>][</b>-br<b>]</b><i> file1 file2</i></code></pre></blockquote><h4><a name = "tag_001_014_417"> </a>DESCRIPTION</h4><blockquote>The<i>diff</i>utility will compare the contents of<i>file1</i>and<i>file2</i>and write to standard outputa list of changes necessary to convert<i>file1</i>into<i>file2</i>.This list should be minimal.No output will be produced if the files are identical.</blockquote><h4><a name = "tag_001_014_418"> </a>OPTIONS</h4><blockquote>The<i>diff</i>utility supports the <b>XBD</b> specification, <a href="../xbd/utilconv.html#usg"><b>Utility Syntax Guidelines</b> </a> .<p>The following options are supported:<dl compact><dt><b>-b</b><dd>Cause any amount of white space at the endof a line to be treated as a singlenewline character(that is, the white-space characters preceding thenewline characterare ignored) andother strings of white-space characters, not includingnewline characters,to compare equal.<dt><b>-c</b><dd>Produce output in a form that provides three lines of context.<dt><b>-C </b><i>n</i><dd>Produce output in a form that provides<i>n</i>lines of context(where<i>n</i>will be interpreted as a positive decimal integer).<dt><b>-e</b><dd>Produce output in a form suitable as input for the<i><a href="ed.html">ed</a></i>utility,which can then be used to convert<i>file1</i>into<i>file2</i>.<dt><b>-f</b><dd>Produce output in an alternative form,similar in format to<b>-e</b>,but unsuitable as input for the<i><a href="ed.html">ed</a></i>utility, and in the opposite order.<dt><b>-r</b><dd>Apply<i>diff</i>recursively to files and directories of the same name when<i>file1</i>and<i>file2</i>are both directories.</dl></blockquote><h4><a name = "tag_001_014_419"> </a>OPERANDS</h4><blockquote>The following operands are supported:<dl compact><dt><i>file1</i><dd><dt><i>file2</i><dd>A pathname of a file be compared.If either the<i>file1</i>or<i>file2</i>operand is "-", the standard input will be used in its place.</dl><p>If both<i>file1</i>and<i>file2</i>are directories,<i>diff</i>will not compare block special files, character special files orFIFO special files to any files andwill not compare regular files to directories.The system documentation will specify the behaviour of<i>diff</i>on implementation-dependent file types notspecified by the <b>XSH</b> specification when found in directories.Further details are as specified in<xref href=diffdir><a href="#tag_001_014_424_001">Diff Directory Comparison Format</a></xref>.<p>If only one of<i>file1</i>and<i>file2</i>is a directory,<i>diff</i>will be applied to the non-directory file and the file containedin the directory file with a filename that is the same as the lastcomponent of the non-directory file.</blockquote><h4><a name = "tag_001_014_420"> </a>STDIN</h4><blockquote>The standard input will be used only if one of the<i>file1</i>or<i>file2</i>operands references standard input.See the INPUT FILES section.</blockquote><h4><a name = "tag_001_014_421"> </a>INPUT FILES</h4><blockquote>The input files must be text files.</blockquote><h4><a name = "tag_001_014_422"> </a>ENVIRONMENT VARIABLES</h4><blockquote>The following environment variables affect the execution of<i>diff</i>:<dl compact><dt><i>LANG</i><dd>Provide a default value for the internationalisation variablesthat are unset or null.If<i>LANG</i>is unset or null, the corresponding value from theimplementation-dependent default locale will be used.If any of the internationalisation variables contains an invalid setting, theutility will behave as if none of the variables had been defined.<dt><i>LC_ALL</i><dd>If set to a non-empty string value,override the values of all the other internationalisation variables.<dt><i>LC_CTYPE</i><dd>Determine thelocale for the interpretation of sequences of bytes of text data ascharacters (for example, single- as opposed to multi-byte charactersin arguments and input files).<dt><i>LC_MESSAGES</i><dd>Determine the locale that should be used to affectthe format and contents of diagnosticmessages written to standard errorand informative messages written to standard output.<dt><i>LC_TIME</i><dd>Determine the locale for affectingthe format of file timestamps written with the<b>-C</b>and<b>-c</b>options.<dt><i>NLSPATH</i><dd>Determine the location of message cataloguesfor the processing of<i>LC_MESSAGES .</i><dt><i>TZ</i><dd>Determine the locale for affectingthe timezone used for calculating file timestamps written with the<b>-C</b>and<b>-c</b>options.</dl></blockquote><h4><a name = "tag_001_014_423"> </a>ASYNCHRONOUS EVENTS</h4><blockquote>Default.</blockquote><h4><a name = "tag_001_014_424"> </a>STDOUT</h4><blockquote><h5><a name = "tag_001_014_424_001"> </a>Diff Directory Comparison Format</h5><xref type="5" name="diffdir"></xref>If both<i>file1</i>and<i>file2</i>are directories,the following output formats will be used.<p>In the POSIX locale,each file that is present in only one directorywill be reported using the following format:<p><code><tt>"Only in %s: %s\n"</tt>, <<i>directory pathname</i>>,<<i>filename</i>></code><p>In the POSIX locale,subdirectories that are common to the two directoriesmay be reported with the following format:<p><code><pre><tt>"Common subdirectories: %s and %s\n"</tt>, <<i>directory1 pathname</i>>,<<i>directory2 pathname</i>></pre></code><p>For each file common to the two directoriesif the two files are not to be compared,the following format shall be used in the POSIX locale:<p><code><pre><tt>"File %s is a %s while file %s is a %s\n"</tt>, <<i>directory1 pathname</i>>,<<i>file type of directory1 pathname</i>>,<<i>directory2 pathname</i>>,<<i>file type of directory2 pathname</i>></code></pre><p>For each file common to the two directories,if the files are to be compared andare identical, no output shall be written.If the two files differ, the following format shall be written:<p><code><tt>"diff %s %s %s\n"</tt>, <<i>diff_options</i>>,<<i>filename1</i>>,<<i>filename2</i>></code><p>where<<i>diff_options</i>>are the options as specified on the command line.Depending on these options, one of the followingoutput formats will be used to write the differences.<p>All directory pathnames listed in this section will be relative tothe original command line arguments.All other names of files listed in this section will be filenames(pathname components).<h5><a name = "tag_001_014_424_002"> </a>Diff Default Output Format</h5>The default (without<b>-e</b>,<b>-f</b>,<b>-c</b>or<b>-C</b>options)<i>diff</i>utility output contains lines of these forms:<p><code><tt>"%da%d\n"</tt>, <<i>num1</i>>,<<i>num2</i>></code><p><code><tt>"%da%d,%d\n"</tt>, <<i>num1</i>>,<<i>num2</i>>,<<i>num3</i>></code><p><code><tt>"%dd%d\n"</tt>, <<i>num1</i>>,<<i>num2</i>></code><p><code><tt>"%d,%dd%d\n"</tt>, <<i>num1</i>>,<<i>num2</i>>,<<i>num3</i>></code><p><code><tt>"%dc%d\n"</tt>, <<i>num1</i>>,<<i>num2</i>></code><p><code><tt>"%d,%dc%d\n"</tt>, <<i>num1</i>>,<<i>num2</i>>,<<i>num3</i>></code><p><code><tt>"%dc%d,%d\n"</tt>, <<i>num1</i>>,<<i>num2</i>>,<<i>num3</i>></code><p><code><tt>"%d,%dc%d,%d\n"</tt>, <<i>num1</i>>,<<i>num2</i>>,<<i>num3</i>>,<<i>num4</i>></code><p>These lines resemble<i><a href="ed.html">ed</a></i>subcommands to convert<i>file1</i>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -