Linux patch命令:应用一个diff文件
Linux patch命令 功能描述
使用patch命令可以应用一个包含差异列表的用diff程序生成的补丁文件,从而可以实现升级。
Linux patch命令 语法
patch [选项] [original文件[patch文件]]
patch [选项] <[patch文件]
命令中各选项的含义如下表所示。
Linux patch命令 示例
应用补丁文件
[root@rhel ~]# cat /root/a1
aaa
bbb
[root@rhel ~]# cat /root/a2
aaa
ccc
[root@rhel ~]# diff -ruN /root/a1 /root/a2 >/root/a.diff
//比较/root/a1和/root/a2文件的不同,生成差异文件/root/a.diff
[root@rhel ~]# patch -p1</root/a.diff
can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|---/root/a12014-07-07 14:37:46.137157231+0800
|+++/root/a22014-07-07 14:37:52.759156785+0800
--------------------------
File to patch: /root/a2 //输入/root/a2
patching file /root/a2
Reversed(or previously applied)patch detected! Assume-R?[n]y //输入y确认
//这样就以/root/a1文件的内容更新/root/a2文件
[root@rhel ~]# cat /root/a2
aaa
bbb