Skip to content

Instantly share code, notes, and snippets.

@pal
Created March 20, 2011 18:02
Show Gist options
  • Save pal/878499 to your computer and use it in GitHub Desktop.
Save pal/878499 to your computer and use it in GitHub Desktop.
Removes duplicate files (found using SHA1 checksum)
#!/bin/bash
# Used in an Automator action that is run as a Image Capture Plugin after file organization
#Delete duplicate files starting at $1 recursive
SRC_DIR=${1:-"$HOME/Backuped/originals/pictures"} # defaults to "$HOME/Backuped/originals/pictures"
temp_file="/tmp/fl$$" # $$ is process ID
find "$SRC_DIR" -type f -exec shasum {} \; | sort -r > $temp_file
# use substr($0, index($0, " ")); instead of $2 to handle filenames with spaces
awk 'a[$1]++ {gsub(/^\*/,"",$2); print "rm ", substr($0, index($0, " "));}' $temp_file | sh
@pal
Copy link
Author

pal commented Apr 1, 2011

Should probably do a check if images are identical sans EXIF data, and if they are, try merge of EXIF?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment