Linux笔记diff

diff - compare files line by line 比较文件,从前往后比较

语法
SYNOPSIS
       diff [OPTION]... FILES
  • -q, --brief 文件 和 文件 不相同时,输出信息
[root@myhost ~]# diff -q test.txt test_1.txt 
文件 tesk.txt  tesk_1.txt 不同
[root@myhost ~]# cat test.txt 
name age
David 18
Jack 20
Lisa 32
[root@myhost ~]# cat test_1.txt 
name age
David 18
Jack 20
Lisa 32
Bob 50
Michel 20
  • -s, 如果条件成立,返回:文件 file.txt 和 filetest.txt 相同,如果不同忽略选项
 - [root@myhost ~]# diff -s test.txt test_1.txt 
4a5,6
> Bob 50
> Michel 20
  • -c, -C NUM, --context[=NUM] ``
 diff -C 2 test.txt test_1.txt 
*** test.txt	2020-07-05 14:49:56.342000000 +0800
--- test_1.txt	2020-07-05 14:37:52.580000000 +0800
***************
*** 1,5 ****
  name age
  David 18
- Pack 22
  Jack 20
  Lisa 32
--- 1,6 ----
  name age
  David 18
  Jack 20
  Lisa 32
+ Bob 50
+ Michel 20

-u, -U NUM, --unified[=NUM] 较之-C选项

[root@myhost ~]# diff -U  2 test.txt test_1.txt 
--- test.txt	2020-07-05 14:49:56.342000000 +0800
+++ test_1.txt	2020-07-05 14:37:52.580000000 +0800
@@ -1,5 +1,6 @@
 name age
 David 18
-Pack 22
 Jack 20
 Lisa 32
+Bob 50
+Michel 20
  • -y, --side-by-side
[root@myhost ~]# diff -y test.txt test_1.txt 
name age							name age
David 18							David 18
Pack 22							      <
Jack 20								Jack 20
Lisa 32								Lisa 32
							      >	Bob 50
							      >	Michel 20
  • -W, --width=NUM 宽度
[root@myhost ~]# diff -y -W  34  test.txt test_1.txt 
name age	name age
David 18	David 18
Pack 22	      <
Jack 20		Jack 20
Lisa 32		Lisa 32
	      >	Bob 50
	      >	Michel 20
  • -a, --text treat all files as text
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值