Skip to content

Recursive switch now needed/available. File paths with spaces. #1

@trimitri

Description

@trimitri

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 folderB

The 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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions