随笔 - 277  文章 - 35  评论 - 868 

!/bin/bash
#if ["$1" = ""]; then
# echo "用法:$0 name1 如:$0 *.jpg 重命名本文件夹下的所有jpg结尾的文件,将@2x替换为空字符串"
# exit
#fi

count=0

#ls | sed "s:^:`pwd`/: "
#for fileName in $(ls -R | sed "s:^:`pwd`/:")
for fileName in $(find ./ *.jpg | grep -v git)
do
#echo $fileName
#continue
if [[ $fileName == *@3x ]]; then
echo "${fileName}是个文件夹,不重命名"
continue;
fi
newFileName=`echo ${fileName//@3x./.}`
mv "./$fileName" "./$newFileName"
# 2> /dev/null
if [ "$fileName" != "$newFileName" ]; then
let count++
echo "找到文件:$fileName,重命名后:$newFileName"
else
echo "找到文件:$fileName,无需重命名"
fi
done

echo "一共重命名了${count}个文件"

posted on 2017-03-29 10:11 WNFK 阅读(...) 评论(...) 编辑 收藏