在linux中找到重复文件夹的最快方法

时间:2015-12-13 15:43:35

标签: linux bash find

在linux文件系统中查找重复文件夹的最快方法是什么? 这是我的想法,我知道这不是高效的 在这里它是它的小突发码:

start from on directory named d1
put file names in d1 into an array.
for i in array
do
   node=`find -iname $i`
   father=father of node
   check if the $father is that specific directory.
done

不完整。
什么是最有效的方法呢?

1 个答案:

答案 0 :(得分:1)

试试这个:

shopt -s dotglob

for file in "$1"/*; do [[ -f "$file" ]] && d1+=( "$(md5sum < "$file")" ); done
for file in "$2"/*; do [[ -f "$file" ]] && d2+=( "$(md5sum < "$file")" ); done 

[[ "$(sort <<< "${d1[*]}")" == "$(sort <<< "${d2[*]}")" ]] && echo "Same" || echo "Different"

以下是它的工作原理:

$ mkdir 1 2
$ ./comparedirs 1 2
Same
$ cat > 1/1 <<< foo
$ cat > 2/1 <<< foo
$ ./comparedirs 1 2
Same
$ cat > 2/1 <<< bar
$ ./comparedirs 1 2
Different