Linux 命令 - patch命令(修补文件)
简介
- Linux patch命令用于修补文件。
- patch指令让用户利用设置修补文件的方式,修改,更新原始文件。
- 参考文章: https://www.runoob.com/linux/linux-comm-patch.html
实例
实例1:修补文件
- 自定义测试文件
[root@ test_patch]# echo linux > file
[root@ test_patch]# cat > file1 << EOF
> linux
> redhat
> EOF
[root@ test_patch]#
-
修补文件
- " diff file file1 > test.patch " :对比文件差异生成补丁文件
- " patch file test.patch " : 升级原文件(file)
[root@ test_patch]# diff file file1 > test.patch
[root@ test_patch]# patch file test.patch
patching file file
[root@ test_patch]# cat file
linux
redhat
[root@ test_patch]#
实例2:备份原文件的修补文件
- " -b " 参数,可以在升级原文件前备份原文件。
- " patch -b file test.patch " : 升级原文件(file) 前 备份原文件(file.orig)。
[root@ test_patch]# patch -b file test.patch
patching file file
[root@ test_patch]# ls
file file1 file.orig test.patch
[root@ test_patch]# cat file.orig
linux
[root@ test_patch]# cat file
linux
redhat
[root@ test_patch]#