批量修改文件名后缀,例html修改成HTML
把文件后缀名html全部修改成HTML:
例:aa.html aa.HTML #!/bin/bash
for file in `ls`;do
mv $file `echo $file | sed -e "s#aa#bb#g" -e "s#html#HTML#g"`
done
"s#aa#bb#g" 匹配 aa字段 "s#html#HTML#g" 匹配 HTML字段
方法二:
#!/bin/bash
for i in `ls /tmp/test1/`;do
f=`echo $i |awk -F . '{print $1}'`
mv $i $f.jpg
done
方法三:
[root@bogon ~]# ls
.txt .txt .txt .txt .txt a.txt
[root@bogon ~]# rename ".txt" ".TXT" *.txt
[root@bogon ~]# ls
.TXT .TXT .TXT .TXT .TXT a.TXT
方法四:
批量重命名文件的扩展名//%表示文件名的结尾,#表示文件名的开头
[root@bogon ~]# ls
a.txt b.txt c.txt d.txt e.txt f.txt g.txt
[root@bogon ~]# for file in `ls *.txt`;do mv $file ${file/%txt/TXT};done
[root@bogon ~]# ls
a.TXT b.TXT c.TXT d.TXT e.TXT f.TXT g.TXT
[root@bogon ~]#