#!/bin/bash
echo "Start Modify the name of png and jpg files"
echo "-------------------------------------------"
count=0
for file in `ls ./`
do
string=${file}
afterpix="${string:${#string} - 4:${#string}}"
png='.png'
jpg='.jpg'
if [ ${afterpix} = ${png} ]
then
mv $file $count.png
count=$[$count+1]
elif [ ${afterpix} = ${jpg} ]
then
mv $file $count.jpg
count=$[$count+1]
fi
done
echo "-------------------------------------------"
echo "Modify Compelete!"
将脚本放置在图片所在目录,命名脚本名(任意),如ModifyPicsName.sh
执行脚本:
- 方式一 :$ chmod +x ModifyPicsName.sh; ./ModifyPicsName.sh
- 方式二 :$ bash ModifyPicsName.sh