patch
patch功能说明:修补文件。
语 法:patch [-bceEflnNRstTuvZ][-B <备份字首字符串>][-d <工作目录>][-D <标示符号>][-F <监别列数>][-g <控制数值>][-i <修补文件>][-o <输出文件>][-p <剥离层级>][-r <拒绝文件>][-V <备份方式>][-Y <备份字首字符串>][-z <备份字尾字符串>][--backup-if -mismatch][--binary][--help][--nobackup-if-mismatch][--verbose][原始文件 <修补文件>] 或 path [-p <剥离层级>] < [修补文件]
补充说明:patch指令让用户利用设置修补文件的方式,修改,更新原始文件。倘若一次仅修改一个文件,可直接在指令列中下达指令依序执行。如果配合修补文件的方式则能一次修补大批文件,这也是Linux系统核心的升级方法之一。
参 数:
-b或--backup 备份每一个原始文件。
-B<备份字首字符串>或--prefix=<备份字首字符串> 设置文件备份时,附加在文件名称前面的字首字符串,该字符串可以是路径名称。
-c或--context 把修补数据解译成关联性的差异。
-d<工作目录>或--directory=<工作目录> 设置工作目录。
-D<标示符号>或--ifdef=<标示符号> 用指定的符号把改变的地方标示出来。
-e或--ed 把修补数据解译成ed指令可用的叙述文件。
-E或--remove-empty-files 若修补过后输出的文件其内容是一片空白,则移除该文件。
-f或--force 此参数的效果和指定"-t"参数类似,但会假设修补数据的版本为新 版本。
-F<监别列数>或--fuzz<监别列数> 设置监别列数的最大值。
-g<控制数值>或--get=<控制数值> 设置以RSC或SCCS控制修补作业。
-i<修补文件>或--input=<修补文件> 读取指定的修补问家你。
-l或--ignore-whitespace 忽略修补数据与输入数据的跳格,空格字符。
-n或--normal 把修补数据解译成一般性的差异。
-N或--forward 忽略修补的数据较原始文件的版本更旧,或该版本的修补数据已使 用过。
-o<输出文件>或--output=<输出文件> 设置输出文件的名称,修补过的文件会以该名称存放。
-p<剥离层级>或--strip=<剥离层级> 设置欲剥离几层路径名称。
-f<拒绝文件>或--reject-file=<拒绝文件> 设置保存拒绝修补相关信息的文件名称,预设的文件名称为.rej。
-R或--reverse 假设修补数据是由新旧文件交换位置而产生。
-s或--quiet或--silent 不显示指令执行过程,除非发生错误。
-t或--batch 自动略过错误,不询问任何问题。
-T或--set-time 此参数的效果和指定"-Z"参数类似,但以本地时间为主。
-u或--unified 把修补数据解译成一致化的差异。
-v或--version 显示版本信息。
-V<备份方式>或--version-control=<备份方式> 用"-b"参数备份目标文件后,备份文件的字尾会被加上一个备份字符串,这个字符串不仅可用"-z"参数变更,当使用"-V"参数指定不同备份方式时,也会产生不同字尾的备份字符串。
-Y<备份字首字符串>或--basename-prefix=--<备份字首字符串> 设置文件备份时,附加在文件基本名称开头的字首字符串。
-z<备份字尾字符串>或--suffix=<备份字尾字符串> 此参数的效果和指定"-B"参数类似,差别在于修补作业使用的路径与文件名若为src/linux/fs/super.c,加上"backup/"字符串后,文件super.c会备份于/src/linux/fs/backup目录里。
-Z或--set-utc 把修补过的文件更改,存取时间设为UTC。
--backup-if-mismatch 在修补数据不完全吻合,且没有刻意指定要备份文件时,才备份文件。
--binary 以二进制模式读写数据,而不通过标准输出设备。
--help 在线帮助。
--nobackup-if-mismatch 在修补数据不完全吻合,且没有刻意指定要备份文件时,不要备份文件。
--verbose 详细显示指令的执行过程。
patch
patch [options] [original [patchfile] ]
Apply the patches specified in patchfile to original. Replace the original with the new, patched version; move the original to original.orig or original~. The patch file is a difference listing produced by the diff command.
Options
Back up the original file.
When not backing up all original files, these options control whether a backup should be made when a patch does not match the original file. The default is to make backups unless --posix is specified.
Interpret patchfile as a context diff.
cd to directory before beginning patch operations.
Print results of applying a patch, but don't change any files.
Treat the contents of patchfile as ed commands.
Force all changes, even those that look incorrect. Skip patches if the original file does not exist; force patches for files with the wrong version specified; assume patches are never reversed.
Specify whether to check the original file out of source control if it is missing or read-only. If num is a positive number, get the file. If it is negative, prompt the user. If it is 0, do not check files out of source control. The default is negative or the value of the PATCH_GET environment variable when set, unless the --posix option is given. In that case, the default is 0.
Print help message, then exit.
Read patch from file instead of stdin.
Ignore whitespace while pattern matching.
Interpret patch file as a normal diff.
Print output to file.
Specify how much of preceding pathname to strip. A num of 0 strips everything, leaving just the filename. 1 strips the leading /. Each higher number after that strips another directory from the left.
Set the quoting style used when printing names. The default style is shell, unless set by the environment variable QUOTING_STYLE. style may be one of the following:
c Quote as a C language string.
escape Like c, but without surrounding double-quote characters.
literal Print without quoting.
shell Quote for use in shell when needed.
shell-always Quote for use in shell even if not needed.
Conform more strictly to the POSIX standard.
Place rejects (hunks of the patch file that patch fails to place within the original file) in file. Default is original.rej.
Suppress commentary.
Skip patches if the original file does not exist.
Interpret patch file as a unified context diff.
Verbose mode.
Print version number and exit.
Back up the original file in original.suffix.
Prepend prefix to the backup filename.
Mark all changes with:
#ifdef string #endif
If patch creates any empty files, delete them.
Specify the maximum number of lines that may be ignored (fuzzed over) when deciding where to install a hunk of code. The default is 2. Meaningful only with context diffs.
Ignore patches that appear to be reversed or to have already been applied.
Do a reverse patch: attempt to undo the damage done by patching with the old and new files reversed.
When original file timestamps match the times given in the patch header, set timestamps for patched files according to the context diff headers. Use option -f to force date changes. Assume timestamps are in local time.
Specify method for creating backup files (overridden by -B):
t, numbered Make numbered backups.
nil, existing Back up files according to preexisting backup schemes, with simple backups as the default. This is patch's default behavior.
never, simple Make simple backups.
Use the specified prefix with a file's basename to create backup filenames. Useful for specifying a directory.
When original file timestamps match the times given in the patch header, set timestamps for patched files according to the context diff headers. Use option -f to force date changes. Assume timestamps are in Coordinated Universal Time (UTC).
Environment variables
Specify the directory for temporary files; /tmp by default.
Suffix to append to backup files instead of .orig or ~.
Specify how output should be quoted (see --quoting-style).
Specify whether patch should retrieve missing or read-only files from source control (see -g).
When set, patch conforms more strictly to the POSIX standard (see --posix).
Specify what method to use in naming backups (see -V).