手机
当前位置:查字典教程网 >脚本专栏 >linuxshell >bash批量重命名、批量更改后辍的方法
bash批量重命名、批量更改后辍的方法
摘要:用特定的格式重命名当前目录的图像文件,脚本如下:复制代码代码如下:#!/bin/bash#Filename:rename_photo.shs...

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

复制代码 代码如下:

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

【bash批量重命名、批量更改后辍的方法】相关文章:

shell中使用echo打印彩色字体和彩色背景的方法

Shell脚本批量重命名文件后缀的3种实现

linux系统mysql自动备份并使用ftp上传的方法

Linux下启动tomcat的方法

sed或awk处理文件最后一行的实现方法

shell中删除文件中重复行的方法

Shell处理带空格的文件名的方法

Shell脚本中引用、调用另一个脚本文件的2种方法

Shell脚本实现批量替换文件内容

bash脚本中if语句的使用方法

精品推荐
分类导航