#!/bin/bash
#遍历目录函数
list_alldir(){
for road in `ls -a $1`
do
if [ x"$road" != x"." -a x"$road" != x".." ];then
if [ -d "$1/$road" ];then
echo "$1/$road"
list_alldir "$1/$road"
fi
fi
done
}
echo "输入文件A的根目录:"
read path_A
list_alldir $path_A >Adir.txt
echo "输入文件B的根目录:"
read path_B
list_alldir $path_B >Bdir.txt
#选择其中一个作为比较标准
files=$(ls $path_A/* $path_A/* )
#用剩下的一个与标准比较
for file in $files
do
filename=$(basename $file ) #通过basename可以通过文件的绝对路径获取文件名
path_B=${path_B}/${filename}
diff ${file} ${path_B} 1>test.txt 2>&1 && result=0 || result=1
if [ "$result" == 1 ];then
# echo "$filename is diff"
exit 0
fi
done
#执行脚本时,赋予权限:chmod -R 777 123.sh
# 执行:./123.sh
# /usr/local
# /etc/local
#比较出来的结果在test.txt文件中