linux命令: patch

Posted oucaijun

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux命令: patch相关的知识,希望对你有一定的参考价值。

 

一. 针对单文件的patch:

我们以mkprj.sh.1和mkprj.sh两个文件为例:

[[email protected] tst]# ls
mkprj.sh.1  mkprj.sh

看两个文件的差异:
[[email protected] tst]# diff mkprj.sh mkprj.sh.1
20,21c20
< cd $workdir/fornew; mkdir crosstools kernel nfs_root uboot;
< cd $workdir/farsight; mkdir crosstools kernel nfs_root uboot;
---
> cd $workdir/farsight1; mkdir crosstools kernel nfs_root uboot;
23c22
<
---
> cd $workdir/configs2;

1. 做补丁patch
[[email protected] tst]# diff mkprj.sh mkprj.sh.1  > mk_patch
2. 打补丁patch

[[email protected] tst]# patch mkprj.sh < mk_patch
patching file mkprj.sh

观察两个文件,已经相同:
[[email protected] tst]# diff mkprj.sh mkprj.sh.1 

3. 卸载补丁patch

[[email protected] tst]# patch -R mkprj.sh  < mkpatch
patching file mkprj.sh

观察两个文件,mkprj.sh又变回原来的样子了.
[[email protected] tst]# diff mkprj.sh mkprj.sh.1
20,21c20
< cd $workdir/fornew; mkdir crosstools kernel nfs_root uboot;
< cd $workdir/farsight; mkdir crosstools kernel nfs_root uboot;
---
> cd $workdir/farsight1; mkdir crosstools kernel nfs_root uboot;
23c22
<
---
> cd $workdir/configs2;

 

二、针对目录的patch

如何制作LINUX的patch文件及如何打patch http://blog.csdn.net/zhenwenxian/article/details/8393731

#ls /work/kernel

linux-2.6.22.6    linux-2.6.22.6_jz2440

1. 做补丁patch

#diff -Naur linux-2.6.22.6/    linux-2.6.22.6_jz2440/   > linux-2.6.22.6_jz2440.patch

#ls /work/kernel

linux-2.6.22.6    linux-2.6.22.6_jz2440   linux-2.6.22.6_jz2440.patch

2. 打补丁patch

#cd /work/kernel/linux-2.6.22.6

  patch -p1 < ../linux-2.6.22.6_jz2440.patch

3. 卸补丁(-R)

  patch -R -p1 < ../linux-2.6.22.6_jz2440.patch

 

以上是关于linux命令: patch的主要内容,如果未能解决你的问题,请参考以下文章

linux查看路径命令

linux查看历史命令记录及时间(linux查看历史命令执行时间)

转载每天一个Linux命令

linux命令中显示之前操作过的所有命令的命令是啥

linux 好用的命令

Linux 命令大全