我是IT悟道,点击右上方“关注”,每天分享IT、科技、数码方面的干货。

patch文件_文件pat_文件管理

Linux patch命令

Linux patch命令用于修补文件。

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指令将文件""升级,其升级补丁文件为".patch",输入如下命令:

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

使用该命令前,可以先使用指令"cat"查看""的内容。在需要修改升级的文件与原文件之间使用指令"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 >. patch"所使用的操作符">"表示将该操作符左边的文件数据写入到右边所指向的文件中。在这里patch文件,即是指将两个文件比较后的结果写入到文件".patch"中。


限时特惠:
本站持续每日更新海量各大内部创业课程,一年会员仅需要98元,全站资源免费下载
点击查看详情

站长微信:Jiucxh

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注