参考:https://www.cnblogs.com/liyuchuan/p/10756066.html

目录结构:

/data/dir1

  subdir/

  subfile

/data/dir2

  subdir/

  subfile

目的是为了判断2个相同结构的文件夹中,有哪些文件的内容是不一样的。

#!/bin/bash
read_dir(){
for file in `ls -a $`
do
if [ -d $"/"$file ]
then
if [[ $file != '.' && $file != '..' ]]
then
read_dir $"/"$file
fi
else diff $"/"$file $(echo $ | sed -e s'/dir1/dir2/')"/"${file} >/dev/null >& && result= || result= if [ "$result" == ];then
echo "$1"/"$file is diff" >> result.log
fi
fi
done
} read_dir /data/dir1
05-27 10:39