shell 批量重命名文件脚本
#!/bin/bash
#author jaycethanks
#description
#执行方式 ./ModifyPicsName <image-type>
#示例: ./ModifyPicsName png jpg jpeg
echo "Start Modify the name of png and jpg files"
echo "-------------------------------------------"
for type in $*
do
count=0
for file in `ls ./*$type`
do
count=$[$count+1]
mv $file $count.$type
echo "modify $file to $count.$type success!"
done
done
echo "-------------------------------------------"
echo "Modify Compelete!"
将脚本放置在文件所在目录,命名脚本名(任意),如创建修改图片的脚本ModifyPicsName.sh
执行脚本:- 方式一 :
$ chmod +x ModifyPicsName.sh; ./ModifyPicsName.sh 文件类型列表
- 方式二 :$ bash ModifyPicsName.sh 文件类型列表
示例:
jayce@DESKTOP-JASQLDM:LHY$ ./ModifyPicsName.sh png jpg jpeg Start Modify the name of png and jpg files ------------------------------------------- modify ./0562gq4h.png to 1.png success! modify ./578634ge.png to 2.png success! modify ./76452467gsf.png to 3.png success! modify ./rxjfsasg.png to 4.png success! modify ./2356yas.jpg to 1.jpg success! modify ./674254gtw.jpg to 2.jpg success! modify ./7i46swh.jpg to 3.jpg success! modify ./asd.jpg to 4.jpg success! modify ./34u737he.jpeg to 1.jpeg success! modify ./gfjkgfjk.jpeg to 2.jpeg success! ------------------------------------------- Modify Compelete!