您的位置:首页 > 其它

使用md5sum比较两目录的文件差异

2018-01-29 14:15 92 查看
find /web/project/ -type f -exec md5sum {} \;>>34.md5.txt
# 获取第一台主机上的某个目录里的所有文件的md5值

find /web/project/ -type f -exec md5sum {} \;>>36.md5.txt
# 获取第二台主机上的某个目录里的所有文件的md5值

cat 34.md5.txt|while read line
do
name1=$(echo "$line"|awk '{print $2}')
md5_1=$(echo "$line"|awk '{print $1}')
name2=$(grep " $name1" 36.md5.txt|awk '{print $2}')
md5_2=$(grep " $name1" 36.md5.txt|awk '{print $1}')
if [ -z "$name2" ]
then
echo "not in 36.md5.txt:  $name1"
else
if [ "$md5_1" != "$md5_2" ]
then
echo "not equal:  $name1 "
fi
fi
done|sort
# 遍历34.md5.txt 查询出不存在于36.md5.txt之中的文件,或两文件都存在,但是不相同的文件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: