如何把目錄下檔名結尾為 .doc 的檔案改名為 .txt ?
可利用以下的 shell script 來完成:
for file in *.doc
do mv -i $file `basename $file .doc`.txt
done
在上面的 script 中,執行 mv 時用了 -i 的選項, 好處在於當要把 a.doc 更名為 a.txt,但 a.txt 已經存在時, mv 將主動詢問你的意見而不會自動覆蓋掉。