Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4255152
  • 博文数量: 1148
  • 博客积分: 25453
  • 博客等级: 上将
  • 技术积分: 11949
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-06 21:14
文章分类

全部博文(1148)

文章存档

2012年(15)

2011年(1078)

2010年(58)

分类: LINUX

2011-10-04 15:57:41

    patch命令用于修补文件。该命令读取如何更改文件的源文件指示信息,然后应用这些更改。源文件包含由diff命令产生的产别列表。差别列表是比较两个文件和构建关于如何纠正差别指示信息的结果。在默认情况下,patch命令使用从标准输入读入源文件

    
    升级文件:
   如果要将文件testfile升级,补丁为testfile.patch,该文件为testfile升级前和修改后文件通过diff命令生成的补丁文件。使用patch为testfile打包的命令为:

  1. ywx@ywx:~/desktop/test/test1$ cat testfile1
  2. hello,this is the first file.
  3. ywx@ywx:~/desktop/test/test1$ cat testfile2
  4. hello,this is the second file.
  5. ywx@ywx:~/desktop/test/test1$ diff testfile1 testfile2
  6. 1c1
  7. < hello,this is the first file.
  8. ---
  9. > hello,this is the second file.
  10. ywx@ywx:~/desktop/test/test1$ diff testfile1 testfile2 > testfile.patch
  11. ywx@ywx:~/desktop/test/test1$ cat testfile.patch
  12. 1c1
  13. < hello,this is the first file.
  14. ---
  15. > hello,this is the second file.
  16. ywx@ywx:~/desktop/test/test1$ patch testfile1 < testfile.patch       使用补丁包升级testfile1文件
  17. patching file testfile1
  18. ywx@ywx:~/desktop/test/test1$ cat testfile1
  19. hello,this is the second file.
  20. ywx@ywx:~/desktop/test/test1$
我们可以使用两种方式来 打补丁

  1. ywx@ywx:~/desktop/test/test1$ cat testfile3
  2. hello,this is the first file.
  3. linux
  4. ywx@ywx:~/desktop/test/test1$ patch testfile3 < testfile.patch
  5. patching file testfile3
  6. ywx@ywx:~/desktop/test/test1$ cat testfile3
  7. hello,this is the second file.
  8. linux
  9. ywx@ywx:~/desktop/test/test1$ cat testfile4
  10. hello,this is the first file.
  11. linux
  12. ywx@ywx:~/desktop/test/test1$ patch -p0 testfile4 testfile.patch
  13. patching file testfile4
  14. ywx@ywx:~/desktop/test/test1$ cat testfile4
  15. hello,this is the second file.
  16. linux
  17. ywx@ywx:~/desktop/test/test1$

如果要打补丁的文件和patch不符合,补丁将失败
  1. ywx@ywx:~/desktop/test/test1$ cat testfile5
  2. hi,this is the first file.
  3. linux
  4. ywx@ywx:~/desktop/test/test1$ patch -p0 testfile5 testfile.patch
  5. patching file testfile5
  6. Hunk #1 FAILED at 1.
  7. 1 out of 1 hunk FAILED -- saving rejects to file testfile5.rej   失败
  8. ywx@ywx:~/desktop/test/test1$



阅读(1418) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~