使用 shell 脚本从两个目录中查找和移动重复文件

Finding and Moving Duplicate Files from two Directories using shell script

嘿,我有三个文件夹

1 : Landing Folder
2 : Completed Folder
3 : Duplicates Folder

我想比较 1 和 2 中的文件是否重复。如果发现重复项,我想将重复文件移动到 3.

有没有什么方法可以使用 Shell 脚本来做到这一点?

我尝试但没有成功的方法是在 1 和 2 上使用 ls >file_names.txt 来获取文本文件中的文件名,这样我就可以比较文本文件中的重复记录。我在 echo 命令中得到了重复列表,不知道如何移动它们。

如果文件 1 包含文件夹 1 中的文件列表,文件 2 包含文件夹 2 中的文件列表,那么下面的代码将起作用

grep -f file1 file2 | while read line
do 
mv folder1/$line folder3
rm -f folder2/$line
done

目录

all:所有文件(例如 10 个)
一些:一些文件(例如3)

# make sure you are in "all" directory
for file in ./*;
do
if test -f "../some/$file then
    rm $file
fi
done

输出

常见的文件将在一些文件中。
不常见的文件(7 个文件)将保留在“全部”