shell 中 比较 diff

diff 可以用来比较文件和文件夹是否相同

比较文件

diff file1 file2 >/dev/null

比较文件夹

diff -rNaq dir1 dir2 >/dev/null

-r  递归比较所有找到的子目录

-N 把缺少的文件当作空白文件处理

-a  把所有文件当作本文件逐行比较

-q 近输出文件是否有差异,不报告错误

重点是看这里的返回值

if  [ "$?" == "0" ];then
    echo "the file or dir is same!"
else 
     echo "the file or dir is different!"
fi

猜你喜欢

转载自www.cnblogs.com/ivyharding/p/11089866.html