在 linux 中查找重复文件夹的最快方法
Fastest way to find Duplicate folders in linux
在 linux 文件系统中查找重复文件夹的最快方法是什么?
这是我的想法,我知道它效率不高。
这是它的小sudocode:
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
未完成。
最有效的方法是什么?
试试这个:
shopt -s dotglob
for file in ""/*; do [[ -f "$file" ]] && d1+=( "$(md5sum < "$file")" ); done
for file in ""/*; 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
在 linux 文件系统中查找重复文件夹的最快方法是什么?
这是我的想法,我知道它效率不高。
这是它的小sudocode:
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
未完成。
最有效的方法是什么?
试试这个:
shopt -s dotglob
for file in ""/*; do [[ -f "$file" ]] && d1+=( "$(md5sum < "$file")" ); done
for file in ""/*; 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