i want to delete duplicate files based on their MD5 value. I already got the script down below but how do i modify it so it works recursively?
So for example i have folder containing 3 subfolders A B C
I want ALL of those files in ./ ./A/ ./B/ ./C/ checked for their md5 and compared to each other, if a positive match is found just randomly delete either match. In the end no more duplicates exist. I dont care which match gets deleted first.
I hope i expressed what i need to achieve clearly enough, if not, kindly let me know :)
#!/bin/bash
while true
do
echo "Enter the directory:"
read directory
if [ -d $directory ]; then
break
else
echo "Invalid directory"
fi
done
for FILE in `ls $directory`
do
if [ ! -f $FILE ]; then
break;
fi
h=`md5sum $directory/$FILE | awk '{ print $1 }'`
for f in `ls $directory`
do
if [ -f $f ] && [ $FILE != $f ]; then
s=`md5sum $directory/$f | awk '{ print $1 }'`
if [ "$s" = "$h" ]; then
echo Removing $f
rm -rf $directory/$f
fi
fi
done
done
jdupesorfdupesfor Linux) that identify duplicates, hardlink or delete excessive copies.find? Probably also worth usingwhile read FILEinstead offor FILE in $(...)to handle massive lists.