用特定的格式重命名当前目录的图像文件,脚本如下:

复制代码 代码如下:

#!/bin/bash
#Filename:rename_photo.sh
set -x
count=1
for img in *.jpg *.png
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  image_2.jpg  image_3.jpg  image_4.jpg  image_5.jpg
[root@localhost rename]# rename image photo image*
[root@localhost rename]# ls
photo_1.jpg  photo_2.jpg  photo_3.jpg  photo_4.jpg  photo_5.jpg

将扩展名小写的.jpg改为大写.JPG
[root@localhost rename]# rename .jpg .JPG *.jpg
[root@localhost rename]# ls
photo_1.JPG  photo_2.JPG  photo_3.JPG  photo_4.JPG  photo_5.JPG

点赞(125)

评论列表共有 0 条评论

立即
投稿
返回
顶部