shell 批量重命名图片脚本 ModifyPicsName

#!/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

shell 批量重命名图片脚本 ModifyPicsName

上一篇:Linux命令tar的压缩与解压


下一篇:Kali Linux基础操作学习篇——mv