Last active
September 18, 2020 04:44
-
-
Save lxfly2000/37fad819044aa10fa1ff0397840f7c6c to your computer and use it in GitHub Desktop.
删除重复的文件
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
#!/system/bin/sh | |
if (($# < 1)) then | |
echo "未指定路径。" | |
exit 1 | |
fi | |
#通过参数指定一个目录 | |
path=$1 #定义时变量不用加$,而引用时则需要加$,若要避免歧义则需要写成${path}形式,另外=左右不能有空格 | |
#查找带有_?特征的文件名 | |
for file in $path/*_[0-9][0-9].* | |
do #必须顶行首写 | |
if [ -f $file ];then #接do时必须顶行首写 | |
echo 搜索:$file | |
#取出_后面的数字 | |
name=${file%.*} | |
originalname=${name%_*} | |
dupnum=${name##*_} | |
ext=${file##*.} | |
originalpath=$originalname.$ext | |
if [ -f $originalpath ];then | |
originalmd5=`md5sum $originalpath|cut -d ' ' -f1` | |
echo "找到文件:$originalpath (MD5:$originalmd5)" | |
filemd5=`md5sum $file|cut -d ' ' -f1` | |
if [ "$filemd5" = "$originalmd5" ]; then | |
echo "文件相同,$file (MD5:$filemd5)会被删除。" | |
rm $file | |
fi | |
fi | |
#比较所有带有小于该数字后缀的文件名,如果md5一致则删除 | |
else | |
echo $file 已被删除。 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment