shell腳本 批量修改文件名後綴的腳本

實驗素材:
[root@sv7 test]# ls //此目錄下包含全是 .txt結尾的文件,要求所有換成 .doc結尾
1.txt 2.txt 3.txt 4.txt 5.txtvim

編寫腳本
[root@sv7 test]# vim /root/25.shbash

腳本內容:
#!/bin/bash
#定義i的取值範圍,只要是以$1結尾的文件都顯示
#對i執行去尾的操做,並加上新的文件後綴
#ls *.$1要用反引號引發來
for i in ls *.$1
do
mv $i ${ i%.*}.$2 &> /dev/null ide

done測試

賦予執行權限
[root@sv7 test]# chmod +x /root/25.shcode

測試腳本:
[root@sv7 test]# /root/25.sh txt doc
[root@sv7 test]# ls
1.doc 2.doc 3.doc 4.doc 5.docit

相關文章
相關標籤/搜索