Linux 补丁生成与使用
2018-07-18 01:14:38来源:博客园 阅读 ()
我们在升级Linux 内核的时候,难免会接触到补丁的知识。下面对如何生成补丁和如何打补丁作讲解。
生成补丁:
制作 hello.c 和 hello_new.c 两个文件如如下所示。
? diff ls hello.c hello_new.c hello_test.c hi.patch ? diff cat hello.c #include "stdio.h" int main(int argc ,char **argv) { printf("Hello World"); } ? diff cat hello_new.c #include "stdio.h" int main(int argc ,char **argv) { printf("Hello World\n"); return 0; }
使用 diff -uN 命令 进行生成patch
? diff diff -uN hello_new.c hello.c > hi.patch ? diff cat hi.patch --- hello_new.c 2018-07-17 16:58:23.679704122 +0800 +++ hello.c 2018-07-17 16:57:59.190677641 +0800 @@ -1,6 +1,5 @@ #include "stdio.h" int main(int argc ,char **argv) { - printf("Hello World\n"); - return 0; + printf("Hello World"); }
至此,patch 已经创建完毕。
之后,我们进行使用 patch 命令 对 hello.c 文件进行打补丁。
? diff patch -p0 <hi.patch patching file hello.c Reversed (or previously applied) patch detected! Assume -R? [n] y ? diff cat hello.c #include "stdio.h" int main(int argc ,char **argv) { printf("Hello World\n"); return 0; } ? diff ls hello.c hello.c.orig hello_new.c hello_test.c hi.patch ? diff cat hello.c.orig #include "stdio.h" int main(int argc ,char **argv) { printf("Hello World"); } ? diff cat hello.c #include "stdio.h" int main(int argc ,char **argv) { printf("Hello World\n"); return 0; } ? diff
可见,补丁已经成功应用,并且生成了 .orig 源文件。 --backup-if-mismatch 选项,可以不进行生成orig 文件。
? diff patch -p0 --no-backup-if-mismatch < hi.patch patching file hello.c Reversed (or previously applied) patch detected! Assume -R? [n] y ? diff ls hello.c hello_new.c hello_test.c hi.patch ? diff cat hello.c #include "stdio.h" int main(int argc ,char **argv) { printf("Hello World\n"); return 0; }
diff 和 patch 命令介绍:
-pnum or --strip=num
Strip the smallest prefix containing num leading slashes from each file name found in the patch file. A sequence of one or more adjacent slashes is counted as a
single slash. This controls how file names found in the patch file are treated, in case you keep your files in a different directory than the person who sent out
the patch. For example, supposing the file name in the patch file was
/u/howard/src/blurfl/blurfl.c
setting -p0 gives the entire file name unmodified, -p1 gives
u/howard/src/blurfl/blurfl.c
without the leading slash, -p4 gives
blurfl/blurfl.c
and not specifying -p at all just gives you blurfl.c. Whatever you end up with is looked for either in the current directory, or the directory specified by the -d
option.
具体的使用说明,可以使用 man diff 和 man patch 命令来进行查看。
保持更新,转载请注明出处。标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:取shell脚本执行的结果
- Linux系统如何设置开机自动运行脚本? 2020-06-11
- Linux指令和shell脚本 2020-06-11
- 适合开发者的最佳Linux发行版 2020-06-11
- RAID 1 软件实现(Linux 系统) 2020-06-10
- linux各级目录 2020-06-08
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash