📄 patch.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>patch</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_1650"> </a>NAME</h4><blockquote>patch - apply changes to files</blockquote><h4><a name = "tag_001_014_1651"> </a>SYNOPSIS</h4><blockquote><pre><code>patch <b>[</b>-blNR<b>][ </b>-c| -e| -n<b>][</b>-d <i>dir</i><b>][</b>-D <i>define</i><b>][</b>-i <i>patchfile</i><b>][</b>-o <i>outfile</i><b>][</b>-p <i>num</i><b>][</b>-r <i>rejectfile</i><b>][</b><i>file</i><b>]</b></code></pre></blockquote><h4><a name = "tag_001_014_1652"> </a>DESCRIPTION</h4><blockquote>The<i>patch</i>utility reads a source (patch)file containing any of the three forms ofdifference (diff) listings produced by the<i><a href="diff.html">diff</a></i>utility (normal, context or in the style of<i><a href="ed.html">ed</a></i>)and apply those differences to a file.By default,<i>patch</i>reads from the standard input.<p>The<i>patch</i>utility attempts to determine the type of the<i><a href="diff.html">diff</a></i>listing, unless overruled by a<b>-c</b>,<b>-e</b>or<b>-n</b>option.<p>If the patchfile contains more than one patch,<i>patch</i>will attempt to apply each of them as if they came from separatepatch files.(In this case the name of the patch file must be determinable for each<i><a href="diff.html">diff</a></i>listing.)</blockquote><h4><a name = "tag_001_014_1653"> </a>OPTIONS</h4><blockquote>The<i>patch</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>Save a copy of the original contents of each modified file,before the differences are applied, in a file of the samename with the suffix<b>.orig</b>appended to it.If the file already exists, it will be overwritten;if multiple patches are applied to the same file, the<b>.orig</b>file will be writtenonly for the first patch.When the<b>-o</b> <i>outfile</i>option is also specified,<i>file</i><b>.orig</b>will not be created but, if<i>outfile</i>already exists,<i>outfile</i><b>.orig</b>will be created.<dt><b>-c</b><dd>Interpret the patch file as a context difference(the output of the utility<i><a href="diff.html">diff</a></i>when the<b>-c</b>or<b>-C</b>options are specified).<dt><b>-d </b><i>dir</i><dd>Change the current directory to<i>dir</i>before processing as described in the EXTENDED DESCRIPTION section.<dt><b>-D </b><i>define</i><dd>Mark changes with the C preprocessor construct:<pre><code>#ifdef <i>define</i>...#endif</code></pre>The option-argument<i>define</i>will be used as the differentiating symbol.<dt><b>-e</b><dd>Interpret the patch file as an<i><a href="ed.html">ed</a></i>script,rather than a<i><a href="diff.html">diff</a></i>script.<dt><b>-i </b><i>patchfile</i><dd>Read the patch information from the file named by the pathname<i>patchfile</i>,rather than the standard input.<dt><b>-l</b><dd>(The letter ell.)Cause any sequence of blank charactersin the difference script to match any sequence ofblank charactersin the input file.Other characters will be matched exactly.<dt><b>-n</b><dd>Interpret the script as a normal difference.<dt><b>-N</b><dd>Ignore patches where the differences have already been applied to the file;by default, already-applied patches are rejected.<dt><b>-o </b><i>outfile</i><dd>Instead of modifying the files (specified by the<i>file</i>operand or the difference listings) directly, write a copyof the file referenced by each patch, with the appropriatedifferences applied, to<i>outfile</i>.Multiple patchesfor a single file will be applied to the intermediateversions of the file created by any previous patches,and will result in multiple,concatenated versions of the file being written to<i>outfile</i>.<dt><b>-p </b><i>num</i><dd>For all pathnames in the patch file that indicate thenames of files to be patched, delete<i>num</i>pathname components from the beginning of each pathname.If the pathname in the patch file is absolute,any leading slashes are considered the firstcomponent (that is,<b>-p 1</b>removes the leading slashes).Specifying<b>-p 0</b>causes the full pathname to be used.If<b>-p</b>is not specified, only the basename (the finalpathname component) is used.<dt><b>-R</b><dd>Reverse the sense of the patch script; that is,assume that the differencescript was created from the new version to the old version.The<b>-R</b>option cannot be used with<i><a href="ed.html">ed</a></i>scripts.The<i>patch</i>utility attempts to reverse each portion ofthe script before applying it.Rejected differences will be saved in swapped format.If this option is not specified, and untila portion of the patch file is successfully applied,<i>patch</i>attempts to apply each portion in its reversed sense as wellas in its normal sense.If the attempt is successful, the userwill be prompted to determine if the<b>-R</b>option should be set.<dt><b>-r </b><i>rejectfile</i><dd>Override the default reject filename.In the default case, thereject file will have the samename as the output file, with the suffix<b>.rej</b>appended to it.See<xref href=patchapp><a href="#tag_001_014_1662_003">Patch Application</a></xref>.</dl></blockquote><h4><a name = "tag_001_014_1654"> </a>OPERANDS</h4><blockquote>The following operand is supported:<dl compact><dt><i>file</i><dd>A pathname of a file to patch.</dl></blockquote><h4><a name = "tag_001_014_1655"> </a>STDIN</h4><blockquote>See the INPUT FILES section.</blockquote><h4><a name = "tag_001_014_1656"> </a>INPUT FILES</h4><blockquote>Input files must be text files.</blockquote><h4><a name = "tag_001_014_1657"> </a>ENVIRONMENT VARIABLES</h4><blockquote>The following environment variables affect the execution of<i>patch</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>NLSPATH</i><dd>Determine the location of message cataloguesfor the processing of<i>LC_MESSAGES .</i><dt><i>LC_TIME</i><dd>Determine the locale for recognisingthe format of file timestamps written by the<i><a href="diff.html">diff</a></i>utility in a context-difference input file.</dl></blockquote><h4><a name = "tag_001_014_1658"> </a>ASYNCHRONOUS EVENTS</h4><blockquote>Default.</blockquote><h4><a name = "tag_001_014_1659"> </a>STDOUT</h4><blockquote>Not used.</blockquote><h4><a name = "tag_001_014_1660"> </a>STDERR</h4><blockquote>Used for diagnostic and informational messages.</blockquote><h4><a name = "tag_001_014_1661"> </a>OUTPUT FILES</h4><blockquote>The output of the<i>patch</i>utility,the save files(<b>.orig</b>suffixes) and the reject files(<b>.rej</b>suffixes) will be text files.</blockquote><h4><a name = "tag_001_014_1662"> </a>EXTENDED DESCRIPTION</h4><blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -