-rw-r--r-- 1 root root 28 Jul 13 15:00 a.txt
-rw-r--r-- 1 root root 30 Jul 13 15:00 b.txt
[root@localhost xly]# cat a.txt
hello
123
this is a.txt
456
[root@localhost xly]# cat b.txt
hello!
123
this is b.txt
4567
[root@localhost xly]# diff a.txt b.txt
1c1
< hello
---
> hello!
3,4c3,4
< this is a.txt
< 456
---
> this is b.txt
> 4567
1c1就是指2个文件第一行不一样
<指的是a.txt
>指的是b.txt
#cat diff_two_file#/bin/sbin
file1=/mnt/mmc/test/aa
file2=/mnt/mmc/test/bb
diff $file1 $file2 >/dev/null
if [ $0 == 0 ]then
echo "Both file are same"
else
echo "Both file are different"
fi
$0 是上一执行命令的返回值。
diff 命令返回值为 0,说明两个文件相同, 否则两个文件不相同。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)