-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Great script, thanks for sharing!
I needed to do some adjustments for allowing file paths with spaces. Also, with the new(?) recursion option in findimagedupes, a more streamlined approach could be used:
Calling the script:
findimagedupes --recurse -t 94% --program /home/tmp/rm_dupes.sh folderA folderBThe rm_dupes.sh script, now smaller:
#!/bin/bash
deletefiles=false
echo -e "! deletefiles is set to $deletefiles"
prevSize=0
# split each line by whitespace, loop through and check each file size, select the largest file to keep
for thisEntry in "$@"
do
dupesFound=$((dupesFound+1))
echo - statting "$thisEntry"...
thisSize=$(stat --printf="%s" "$thisEntry")
echo - single found item is "$thisEntry" with file size of "$thisSize" bytes
# find largest file
if [[ "$thisSize" -gt "$prevSize" ]]; then
fileToKeep=$thisEntry
fi
done
echo - largest file is "$fileToKeep", this file will be kept when deleting duplicates
dupesFound=$((dupesFound-1))
echo ---
# now find the files to delete
for thisEntry in "$@"
do
# find largest file
if [[ "$thisEntry" != "$fileToKeep" ]]; then
echo - file to be deleted is "$thisEntry"
# delete file if --delete is passed in
if [[ "$deletefiles" == "true" ]]; then
echo -e " - deleting duplicates"
rm -v "$thisEntry"
deletedFiles=$((deletedFiles+1))
fi
fi
done
echo -----
echo -e " - $dupesFound duplicates found, not including largest original file"
echo -e " - $deletedFiles files deleted."
Metadata
Metadata
Assignees
Labels
No labels