Linux下打补丁patch 和 diff 命令的使用(2)

shell> diff ni.txt wo.txt 1a2 > changqing 3a5 > zhangjiacai shell> diff ni.txt wo.txt >ni-to-wo.patch  //生成补丁文件 shell> patch ni.txt <ni-to-wo.patch  //打补丁 patching file ni.txt shell> diff ni.txt wo.txt  //打补丁成功 shell> patch -R ni.txt <ni-to-wo.patch  //还原到原来的版本(撤销打补丁) patching file ni.txt shell> diff ni.txt wo.txt 1a2 > changqing 3a5 > zhangjiacai

2、目录和目录的比较

[root@localhost linuxidc.com]# tree qq-v1 qq-v1 ├── hosts └── image └── 1.txt [root@localhost linuxidc.com]# tree qq-v2 qq-v2 ├── hosts ├── image │ └── 1.txt ├── passwd └── sound └── 3.txt [root@localhost linuxidc.com]# diff -ur qq-v1 qq-v2 Only in qq-v2: passwd Only in qq-v2/sound: 3.txt [root@localhost linuxidc.com]# diff -Nur qq-v1 qq-v2 diff -Nru qq-v1/passwd qq-v2/passwd --- qq-v1/passwd 1970-01-01 08:00:00.000000000 +0800 +++ qq-v2/passwd 2016-11-02 17:07:47.664980339 +0800 @@ -0,0 +1,31 @@ +root:x:0:0:root:/root:/bin/bash +bin:x:1:1:bin:/bin:/sbin/nologin

解析:

  -N --new-file(Treat absent files as empty)如果没有文件,就拿一个空文件和别的目录里的文件比较

制作补丁文件进行对目录的打补丁

[root@localhost linuxidc.com]# diff -Nur qq-v1 qq-v2 >patch-v2.txt  #比较文件夹生成补丁文件--备用:补丁文件patch-v2.txt在linuxidc.com目录下

-pnum  or  --strip=num

     Strip the smallest prefix containing num leading slashes from each file name 

found in the patch file. 

例如:/a/b/c/d/e/f/g

  -p3 的效果就是去掉第3个/前面的内容,效果:c/d/e/f/g

  -p4 的效果就是去掉第4个/前面的内容,效果:d/e/f/g

1> 内层打补丁

[root@localhost linuxidc.com]# cd qq-v1  #进入qq目录,进去里面进行打补丁 [root@localhost qq-v1]# patch -p1 <../patch-v2.txt patching file passwd patching file sound/3.txt [root@localhost qq-v1]# cd .. [root@localhost linuxidc.com]# diff -Nru qq-v1 qq-v2   //没有输出结果说明打补丁成功 [root@localhost linuxidc.com]# cd qq-v1 [root@localhost qq-v1]# patch -R -p1 <../patch-v2.txt  //撤销补丁 patching file passwd patching file sound/3.txt [root@localhost qq-v1]# cd .. [root@localhost linuxidc.com]# diff -Nru qq-v1 qq-v2 diff -Nru qq-v1/passwd qq-v2/passwd --- qq-v1/passwd 1970-01-01 08:00:00.000000000 +0800 +++ qq-v2/passwd 2016-11-02 17:07:47.664980339 +0800 @@ -0,0 +1,31 @@ +root:x:0:0:root:/root:/bin/bash +bin:x:1:1:bin:/bin:/sbin/nologin

2> 外层打补丁

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/13779.html