脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|shell|

服务器之家 - 脚本之家 - shell - bash批量重命名、批量更改后辍的方法

bash批量重命名、批量更改后辍的方法

2023-02-09 11:44脚本之家 shell

这篇文章主要介绍了bash批量重命名、批量更改后辍的方法,需要的朋友可以参考下

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

复制代码 代码如下:


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

延伸 · 阅读

精彩推荐