这篇文章主要介绍了bash批量重命名、批量更改后辍的方法,需要的朋友可以参考下
用特定的格式重命名当前目录的图像文件,脚本如下:
#!/bin/bash
#Filename:rename_photo.sh
set -x
count=1
for img in *.jpg-600 *.png-600
do
new=image-$count.${img##*.}
mv "$img" "$new" 2> /dev/null
if [ $? -eq 0 ]
then
echo "Renameing $img to $new"
let count++
fi
done
其他的执行重命名的命令:rename
[root@localhost script]# rename image photo image*
将当前目录下所有以image开头的文件,换成以photo开关
[root@localhost rename]# ls
image_1.jpg-600 image_2.jpg-600 image_3.jpg-600 image_4.jpg-600 image_5.jpg-600
[root@localhost rename]# rename image photo image*
[root@localhost rename]# ls
photo_1.jpg-600 photo_2.jpg-600 photo_3.jpg-600 photo_4.jpg-600 photo_5.jpg-600
将扩展名小写的.jpg-600改为大写.JPG
[root@localhost rename]# rename .jpg-600 .JPG *.jpg-600
[root@localhost rename]# ls
photo_1.JPG photo_2.JPG photo_3.JPG photo_4.JPG photo_5.JPG
复制代码 代码如下:
#!/bin/bash
#Filename:rename_photo.sh
set -x
count=1
for img in *.jpg-600 *.png-600
do
new=image-$count.${img##*.}
mv "$img" "$new" 2> /dev/null
if [ $? -eq 0 ]
then
echo "Renameing $img to $new"
let count++
fi
done
其他的执行重命名的命令:rename
复制代码 代码如下:
[root@localhost script]# rename image photo image*
将当前目录下所有以image开头的文件,换成以photo开关
[root@localhost rename]# ls
image_1.jpg-600 image_2.jpg-600 image_3.jpg-600 image_4.jpg-600 image_5.jpg-600
[root@localhost rename]# rename image photo image*
[root@localhost rename]# ls
photo_1.jpg-600 photo_2.jpg-600 photo_3.jpg-600 photo_4.jpg-600 photo_5.jpg-600
将扩展名小写的.jpg-600改为大写.JPG
[root@localhost rename]# rename .jpg-600 .JPG *.jpg-600
[root@localhost rename]# ls
photo_1.JPG photo_2.JPG photo_3.JPG photo_4.JPG photo_5.JPG
以上就是bash批量重命名、批量更改后辍的方法的详细内容,更多请关注0133技术站其它相关文章!