文件处理diff和patch命令简介

diff 比较两个文件的内容

diff -u $file1 $file2

patch -b $file1 $file2

两个命令搭配使用

例.  重定向的f3经过patch -b后生成一个f2的备份文件并将f2的内容还原成被删除的f1文件的内容

[root@xiaoxiao tmpfile]# diff f1 f2
1c1
< aaaa
---
> iiiii
[root@xiaoxiao tmpfile]# diff  -u f1 f2
--- f1  2020-05-28 11:24:08.363011289 -0400
+++ f2  2020-05-28 11:24:59.522012339 -0400
@@ -1,4 +1,4 @@
-aaaa
+iiiii
 bbbbb
 cccc
 ddad
[root@xiaoxiao tmpfile]# diff f1 f2 > f3
[root@xiaoxiao tmpfile]# rm -f f1 
[root@xiaoxiao tmpfile]# patch -b f2 f3
patching file f2
Reversed (or previously applied) patch detected!  Assume -R? [n] yes
[root@xiaoxiao tmpfile]# ls
f2  f2.orig  f3
[root@xiaoxiao tmpfile]# cat f2
aaaa
bbbbb
cccc
ddad
原文地址:https://www.cnblogs.com/hekuangquanshuiweiteng/p/12978877.html