#!/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文件中
相关文章
- Windows下记事本编辑的Shell脚本放到Linux下执行出错,格式问题(/bin/bash^M: bad interpreter: 没有那个文件或目录)
- shell脚本之对比不同目录的下的文件
- shell脚本查找指定目录下所有子目录中的同名文件
- shell脚本——比较不同目录下所有文件
- Linux下使用Shell脚本删除一个目录下的所有子目录和文件
- Linux下使用Shell脚本删除一个目录下的所有子目录和文件
- 实用脚本 4 -- Makefile(不同文件下的多个可执行文件or静态库编译到同一目录下)
- shell脚本——不同目录下同名文件内容比较
- 实用脚本 4 -- Makefile(不同文件下的多个可执行文件or静态库编译到同一目录下)
- 查找具有相同名称和子目录但两个主要目录中的不同内容的文件