轉自http://xiujie.5d6d.com/thread-2985-1-1.html
Shell 文件名大小寫轉換
shell判斷文件,目錄是否存在或者具有權限
在unix系統下經常要碰到改文件名,如果是改單個文件則好處理,但要是批量改文件名則工作量很大,必須運用shell程序來實現,以下程序就是通過shell來實現批量更改日誌文件名的程序,大家可以稍作修改,就可以實現批更改你所需要更改的文件名。
以下就爲程序內容,可供大家學習參考:
class='codetop'>CODE: class='codemain'>#此處SHELL腳本是將CYYMMDD.*的文件批改名爲YYYYMMDD.*的文件 STR="請選擇:" DATE="請輸入日期(031001):" while true echo "1) 批更改文件名" echo "0) 退出/n" printf $STR read anwser do case $anwser in 1) printf $DATE read ndate file1='C'$ndate'.*' #定義FILE1爲C打頭的帶日期的所有文件 #echo $file1 ls $file1 > test.txt out1=`more test.txt|awk '{print $1}'` number=`more test.txt|wc -l` i=1 echo "number = " $number while true do put1=`echo $out1|awk '{print $'$i'}'` put2=`echo $out1|awk '{print substr($'$i',2,10)}'` put2='20'$put2 echo $put1 echo $put2 mv $put1 $put2 i=`expr $i + 1` if [ $i -gt $number ] then break fi done echo "批更改文件成功!/n" ;; 0) exit ;; esac done |