为大量图片重新命名

The easiest way of renaming image files in the current directory to our own filename with a

specific format is by using the following script:


#!/bin/bash
#Filename: rename.sh
#Description: Rename jpg and png files
count=1;
for img in *.jpg *.png
do
new=image-$count.${img##*.}                 #提取图片后序名,和新的名字结合为新的文件名
mv "$img" "$new" 2> /dev/null                   #如果mv的过程中出错,错误信息不显示, “2>”  错误信息重定向
if [ $? -eq 0 ];                                                  # "$?"  检查上一个执行命令成功与否,如果成功则返回0
then
echo "Renaming $img to $new"
let count++
fi

done


The output is as follows:
$ ./rename.sh
Renaming hack.jpg to image-1.jpg
Renaming new.jpg to image-2.jpg
Renaming next.jpg to image-3.jpg
The script renames all the .jpg and .png files in the current directory to new filenames in
the format image-1.jpg, image-2.jpg, image-3.jpg , image-4.png, and so on.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值