English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Linux patch command

Linux Command大全

The Linux patch command is used to patch files.

The patch command allows users to modify and update the original file by setting the patch file. If only one file is modified at a time, the command can be executed sequentially in the command list. If combined with the patch file method, it can patch a large number of files at once, which is also one of the methods for upgrading the Linux system kernel.

syntax

patch [-bceEflnNRstTuvZ][-B <备份字首字符串>][-d <工作目录>][-D <标示符号>][-F <监别列数>][-g <控制数值>][-i <修补文件>][-o <输出文件>][-p <剥离层级>][-r <拒绝文件>][-V <备份方式>][-Y <备份字首字符串>][-z <备份字尾字符串>][--utc  Set the access time of the modified files after patching to UTC.-nobackup -mismatch][--binary][--help][--help  Online help.-nobackup-mismatch][--verbose][original file <修补文件>] or path [-p <剥离层级>] < [修补文件]

parameter

  • -b or--backup  Backup each original file.
  • -B<备份字首字符串> or--prefix=<备份字首字符串>  Set the prefix string to be attached to the file name when backing up files, which can be a path name.
  • -c or--context  Decode the patched data into contextual differences.
  • -d<工作目录> or--directory=<工作目录>  Set the working directory.
  • -D<标示符号> or--ifdef=<标示符号>  Mark the changed places with the specified symbol.
  • -e or--ed  Decode the patched data into a description file that can be used by ed commands.
  • -E or--remove-empty-files  If the output file after patching is blank, remove the file.
  • -f or--force  The effect of this parameter is the same as specifying"-t"parameter similar, but it will assume that the patched data version is the new version.
  • -F<监别列数> or--fuzz<监别列数>  Set the maximum value of the distinguishable column numbers.
  • -g<控制数值> or--get=<控制数值>  Set the patch operation with RSC or SCCS control.
  • -i<修补文件> or--input=<修补文件>  Read the specified patch file.
  • -l or--ignore-whitespace  Ignore the tab and space characters in the patched data compared to the input data.
  • -n or--normal  Decode the patched data into general differences.
  • -N or--forward  Ignore the patched data if it is older than the original file version, or if the patched data of this version has been used.
  • -o<输出文件> or--output=<输出文件>  Set the name of the output file, the patched file will be stored with this name.
  • -p<剥离层级> or--strip=<剥离层级>  Set the path name of the layers to be stripped.
  • -}--f<reject file> or-reject
  • -file=<reject file>  Set the name of the file to save the rejected patch information, the default file name is .rej.--R or
  • -reverse  Assume that the patch data is generated by exchanging the positions of the new and old files.--s or--quiet or
  • -silent  Do not display the execution process of the command unless an error occurs.--t or
  • -batch  Automatically skip errors without asking any questions.--Z or-T or-time  This parameter has the same effect as specifying"
  • -Z"parameter is similar, but mainly uses local time.--u or
  • -unified  Translate the patch data into a unified difference.--v or
  • -version  Display version information.--V<backup method> or-version-control=<backup method>  Using"-b"parameter to backup the target file, the backup file tail will be added with a backup string, this string is not only available"-"parameter changes when using"
  • -V"parameters specify different backup methods, and different backup tail strings are also generated.--Y<backup prefix string> or-basename--prefix=
  • -<backup prefix string>  Set the prefix string to be attached to the file name when backing up the file.--z<backup tail string> or-suffix=<backup tail string>  This parameter has the same effect as specifying"/src/linux/B" parameter is similar, but the difference lies in the path and filename used for the patching job if it is src/super.c, with the "backup/"String, the file super.c will be backed up to/src/linux/fs
  • -backup directory.--Z or-set
  • --utc  Set the access time of the modified files after patching to UTC.-nobackup-backup
  • --mismatch  Backup the file when the patch data does not match completely and no specific backup file is specified.
  • --binary  Read and write data in binary mode without going through the standard output device.
  • --help  Online help.-nobackup-if
  • --mismatch  Do not backup the file when the patch data does not match completely and no specific backup file is specified.

verbose  Display the detailed execution process of the command.

Online example1Use the patch command to upgrade the file "testfile

$ patch -p0 testfile1 testfile.patch    # Use the patch program to upgrade the file 

Before using the command, you can first use the command "cat" to view the "testfile1The content of the patch can be generated by using the "diff" command to compare the file to be modified or upgraded with the original file. The specific operation is as follows:

$ cat testfile1                 #View testfile1content  
Hello,This is the firstfile!  
$ cat testfile2                 #View testfile2content  
Hello,Thisisthesecondfile!  
$ diff testfile1 testfile2          #Compare two files  
1c1  
<Hello,Thisisthefirstfile!  
---  
>Hello,Thisisthesecondfile!  
#Save the comparison results to tetsfile.patch file  
$ diff testfile1 testfile2>testfile.patch     
$ cat testfile.patch                #View the content of the patch package  
1c1  
<Hello,Thisisthefirstfile!  
---  
>Hello,Thisisthesecondfile!  
#Upgrade testfile using patch package1file  
$ patch -p0 testfile1 testfile.patch      
patching file testfile1  
$cat testfile1                  #View testfile again1content  
#testfile1The file has been modified to match testfile2identical content  
Hello,This is the secondfile!   

Note: In the above command code, "$ diff testfile1 testfile2The operator ">" used in "testfile.patch" indicates that the file data on the left of the operator will be written into the file pointed to on the right. Here, it refers to writing the comparison results of the two files into the file "testfile.patch".

Linux Command大全