十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
Linux patch命令用于修补文件。 patch指令让用户利用设置修补文件的方式,修改,更新原始文件。倘若一次仅修改一个文件,可直接在指令列中下达指令依序执行。如果配合修补文件的方式则能一次修补大批文件,这也是Linux系统核心的升级方法之一。

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指令将文件”testfile1″升级,其升级补丁文件为”testfile.patch”,输入如下命令:
$ patch -p0 testfile1 testfile.patch    #使用补丁程序升级文件
使用该命令前,可以先使用指令”cat”查看”testfile1″的内容。在需要修改升级的文件与原文件之间使用指令”diff”比较可以生成补丁文件。具体操作如下所示:
$ cat testfile1                 #查看testfile1的内容  
Hello,This is the firstfile!  
$ cat testfile2                 #查看testfile2的内容  
Hello,Thisisthesecondfile!  
$ diff testfile1 testfile2          #比较两个文件  
1c1  
  
   Hello,Thisisthesecondfile!   
   #将比较结果保存到tetsfile.patch文件   $ diff testfile1 testfile2>testfile.patch     $ cat testfile.patch                
   #查看补丁包的内容   1c1   
   
    Hello,Thisisthesecondfile!   
    #使用补丁包升级testfile1文件   $ patch -p0 testfile1 testfile.patch       patching file testfile1   
    $cat testfile1                  
    #再次查看testfile1的内容   
    #testfile1文件被修改为与testfile2一样的内容   Hello,This is the secondfile!   
   
  注意:上述命令代码中,”$ diff testfile1 testfile2>testfile. patch”所使用的操作符”>”表示将该操作符左边的文件数据写入到右边所指向的文件中。在这里,即是指将两个文件比较后的结果写入到文件”testfile.patch”中。