两个文件夹下面的文件个数及其名称完全一样,但是内容有的可能不一样,这个脚本遍历文件夹下的所有子文件夹,包括嵌套多层的,然后使用linux系统的diff命令对两个名称一样的文件进行比较,脚本如下:
#!/bin/sh
if [ $# -ne 2 ]
then
echo Usage: compare.sh fold_name_1 fold_name_2
exit
fi
if [ ! -d $1 ]
then
echo $1 is not a
exit
fi
if [ ! -d $2 ]
then
echo $2 is not a
exit
fi
fold1=$(echo $1 | sed 's|\(^[^/]*\).*|\1|')
fold2=$(echo $2 | sed 's|\(^[^/]*\).*|\1|')
compareFOLD()
{
for file in $1/*
do
if [ -d $file ] then
compareFOLD $file
elif [ -f $file ]
then
if [ ! -L $file ]
then
file2=$(echo $file | sed "s|^.[^/]*\(.*\)|$fold2\1|")
diff $file $file2
if [ $? -ne 0 ]
then
echo -e "\033[32m"$file
echo $file2
echo -e "\033[0m"---------------------------------------------------------------------
fi
fi
fi
done
}
compareFOLD $fold1
|
阅读(11441) | 评论(1) | 转发(0) |