Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.4: Find potential duplicate files via Spotlight metadata' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Find potential duplicate files via Spotlight metadata
Authored by: hughescr on Oct 13, '06 12:27:26PM
A nice final step would be to go through the list of possible matches and see if the md5sum matches the $1 md5sum:

#!/bin/bash
#
# dupecheck - identified potential duplicates of a file using Spotlight metadata
# by Derick Fay, October 2006
# Extended to check md5sums by Craig Hughes, October 2006

if [ -z $1 ]; then      # -n tests to see if the argument is non empty
        echo "usage: $0 filename"
        exit
fi

# Get the to-match MD5 sum
MD5SUM=`md5sum "$1" | awk '{print $1}'`

#extract metadata from the file to be checked
size=`mdls -name kMDItemFSSize "$1" | tail -n 1 | sed -e 's/^[a-zA-Z ]*= *//'`
name=`mdls -name kMDItemFSName "$1" | tail -n 1 | sed -e 's/^[a-zA-Z ]*= *//'`
kind=`mdls -name kMDItemKind "$1"   | tail -n 1 | sed -e 's/^[a-zA-Z ]*= *//'`

#Get possible matches
echo "MD5-confirmed matches:"
mdfind -0 "kMDItemFSName == $name || (kMDItemFSSize == $size && kMDItemKind=$kind)" | xargs -0 md5sum | grep $MD5SUM | sed -e 's/^[0-9a-f]* *//'


[ Reply to This | # ]
10.4: Find potential duplicate files via Spotlight metadata
Authored by: JadeNB on Apr 25, '07 06:16:51PM
There are several other versions of this script posted below anyway, but, just for anyone who's trying to follow and was confused by this line:
if [ -z $1 ]; then # -n tests to see if the argument is non empty
It is certainly true that -n tests if its argument is non-empty, but, obviously, that's not the test used here. -z is just the opposite test: Is the argument empty?

[ Reply to This | # ]