Last active
August 29, 2015 14:23
-
-
Save ehedaya/e6d8af21512171a0ce98 to your computer and use it in GitHub Desktop.
Copy files with md5 duplicate check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if [[ $1 ]] | |
then | |
# make sure we have required argment | |
echo "Attempting to copy files to $1" | |
else | |
echo "No target destination specified" | |
exit | |
fi | |
echo "Building md5 log" | |
# Unix timestamp filename | |
log=/tmp/md5copylog-`date +%s`.md5 | |
# Empty it, just in case | |
> $log | |
# Build our md5 list by looping through the files in the destination folder and hashing each | |
for f in $1/*; | |
do | |
# generate an md5 for this file | |
m=`md5 -q "$f"` | |
echo -n "." | |
# append it to the log | |
echo $m >> $log | |
done; | |
# now let's try to copy them | |
for f in *; | |
do | |
# generate an md5 for this file | |
m=`md5 -q "$f"` | |
# check if it's in the log file we built | |
if grep -q $m $log | |
then | |
echo "File $f exists in target, will not copy" | |
else | |
echo "File $f does not exist in target, will copy" | |
cp "$f" "$1" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment