The easiest way of renaming image files in the current directory to our own filename with a
#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
$ ./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.
specific format is by using the following script:
#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
$ ./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.