Last active
August 29, 2015 14:08
-
-
Save nyango/b98d707305dc01fc5737 to your computer and use it in GitHub Desktop.
md5sumを用いて重複ファイルを削除するスクリプトを書いた / Using md5sum, this script removes duplicated files
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
#!/bin/bash | |
# this script removes duplicated files | |
# using md5sum. | |
# | |
# $1 : target directory | |
# | |
tmptable=$(mktemp temp.XXXXX) | |
\ls -t ${1%/}/* | while read line | |
do | |
md5 "$line" | sed "s,^MD5 (,," | sed "s/) = / /" | |
done > $tmptable | |
# duplicate check | |
cat $tmptable | awk '{print $NF}' | sort | uniq -c \ | |
| awk '{if($1 > 1) print $NF}' \ | |
| while read ff | |
do | |
cat $tmptable | egrep " $ff$" | sed "s/ $ff$//" | awk 'NR>1{print}' | |
done | while read rmfile | |
do | |
echo "removed "$rmfile | |
rm $rmfile | |
done | |
rm $tmptable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment