您现在的位置是:网站首页> 编程资料编程资料
bash批量重命名、批量更改后辍的方法_linux shell_
2023-05-26
323人已围观
简介 bash批量重命名、批量更改后辍的方法_linux shell_
用特定的格式重命名当前目录的图像文件,脚本如下:
#!/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
复制代码 代码如下:
#!/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
您可能感兴趣的文章:
相关内容
- Shell中处理包含空格的文件名实例_linux shell_
- shell实现FizzBuzzWhizz问题示例(拉勾网面试题)_linux shell_
- vtune自动化安装脚本_linux shell_
- 利用shell删除数据表中指定信息和字段对应的文件_linux shell_
- nginx多server日志分割脚本分享_linux shell_
- 图片批量压缩大小脚本分享_linux shell_
- shell统计pv和uv、独立ip的方法_linux shell_
- 脚本自动添加crontab示例_linux shell_
- bash获取当前路径示例_linux shell_
- shell脚本实现ssh自动登录功能分享_linux shell_
