Latest web development tutorials

Linux patch command

Linux command Daquan Linux command Daquan

Linux patch command for a patch file.

patch instruction set allows users to use patch files, modifications, update the original file. If only one file was last modified, can issue commands directly from the command line are sequentially executed. If the patch file with the way you can repair a large number of files, one of which is the Linux system core upgrade method.

grammar

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 <剥离层级>] < [修补文件]

Parameters:

  • -b backup or --backup each of the original file.
  • -B <Backup prefix string> or --prefix = <backup prefix string> When you set up file backup, appended to the file name prefix in front of the string can be a path name.
  • -c or --context interpreted as the patch data correlation difference.
  • -d <working directory> or --directory = <working directory> set the working directory.
  • -D <Flag symbol> or --ifdef = <label symbol> with the specified symbol to change the place marked.
  • -e or --ed to repair instructions ed data interpreted as described in documents available.
  • File -E or --remove-empty-files after the patch output if its content is blank, then remove the file.
  • -f --force effect of this parameter and the specified or similar "-t" parameter, but will assume version patch data for the new version.
  • -F <Do not monitor the number of columns> or --fuzz <prison do not list the number> Sets the maximum number of columns prison respectively.
  • -g <control value> or --get = <control number> or SCCS control settings to RSC repair work.
  • -i <patch file> or --input = <patch file> reads the specified patches ask you home.
  • -l or --ignore-whitespace Ignore patch data and the input data tabbing, space characters.
  • -n or --normal the patch data interpreted as a general difference.
  • -N --forward Version or ignore repair data files older than the original, or the version of the patch data have been used.
  • -o <output file> or --output = <output file> Set the name of the output file, the file will be patched to the store name.
  • -p <release level> or --strip = <release level> Set To peel layers path name.
  • -f <deny file> or --reject-file = <refused File> Save Settings refuse repair information related to the file name, the default file name is .rej.
  • -R Or --reverse assumptions repair data is generated by the exchange of the old and new file location.
  • -s or --quiet or --silent not displayed during the execution of the instruction, unless an error occurs.
  • -t or --batch automatically skip error, without asking any questions.
  • Effects and specify -T or --set-time parameter like "-Z" parameter, but mainly local time.
  • -u or --unified the patch data interpreted as harmonization of differences.
  • -v or --version display version information.
  • -V <Backup> or --version-control = <backup> After using the "-b" parameter backup target file, the backup file suffix will be coupled with a backup string that can be used not only "-z "parameter change when using the" when -V "parameter to specify a different backup, the backup will produce a string of different suffix.
  • -Y <Backup prefix string> or --basename-prefix = - <backup prefix string> When you set up file backup, the additional prefix string in the file names that start with the basic.
  • -z <backup suffix string> or --suffix = <backup suffix string> effect of this parameter and specify "-B" similar parameters, the difference lies in the path of the repair work using the file name if it is src / linux / fs / super.c, plus the "backup /" after the string, the file will be backed up in super.c / src / linux / fs / backup directory.
  • -Z Or --set-utc the patched file changes, the access time is set to UTC.
  • --backup-if-mismatch repair is not completely consistent in the data, and not trying to specify when you want the backup files before the backup file.
  • --binary read and write data in binary mode, not through the standard output device.
  • --help online help.
  • --nobackup-if-mismatch repair is not completely consistent in the data, and not trying to specify the backup file, do not back up files.
  • --verbose detailed display during the execution of instructions.

Examples

Use patch instruction file "testfile1" upgrade, upgrade patch file "testfile.patch", enter the following command:

$ patch -p0 testfile1 testfile.patch    #使用补丁程序升级文件 

Before using this command, you can use the command "cat" View "testfile1" content. Use instruction between the need to modify the upgrade file with the original file "diff" patch file comparison can be generated. Specific actions are as follows:

$ cat testfile1                 #查看testfile1的内容  
Hello,This is the firstfile!  
$ cat testfile2                 #查看testfile2的内容  
Hello,Thisisthesecondfile!  
$ diff testfile1 testfile2          #比较两个文件  
1c1  
<Hello,Thisisthefirstfile!  
---  
>Hello,Thisisthesecondfile!  
#将比较结果保存到tetsfile.patch文件  
$ diff testfile1 testfile2>testfile.patch     
$ cat testfile.patch                #查看补丁包的内容  
1c1  
<Hello,Thisisthefirstfile!  
---  
>Hello,Thisisthesecondfile!  
#使用补丁包升级testfile1文件  
$ patch -p0 testfile1 testfile.patch      
patching file testfile1  
$cat testfile1                  #再次查看testfile1的内容  
#testfile1文件被修改为与testfile2一样的内容  
Hello,This is the secondfile!   

Note: The above command code, ". $ Diff testfile1 testfile2> testfile patch" used by the operator ">" indicates the left of the operator file data is written to the right of the file pointed to. Here, which means the results of the two files will be written to the file after comparison "testfile.patch" in.

Linux command Daquan Linux command Daquan