shell 批量 修改檔名

awk + xorg

➜ touch file{0..10}.txt
➜ ls
file0.txt file10.txt file1.txt file2.txt file3.txt file4.txt file5.txt file6.txt file7.txt file8.txt file9.txt
➜ ls | awk ‘{print $NF}’ | xargs -I {} mv {} update_{}
➜ ls
update_file0.txt update_file1.txt update_file3.txt update_file5.txt update_file7.txt update_file9.txt
update_file10.txt update_file2.txt update_file4.txt update_file6.txt update_file8.txt

bash
➜ touch file{1..10}.txt
➜ ls
file10.txt file1.txt file2.txt file3.txt file4.txt file5.txt file6.txt file7.txt file8.txt file9.txt
➜ num=0; for i in *; do mv "$i" "$(printf ‘%04d’ $num).${i#*.}"; ((num++)); done
➜ ls
0000.txt 0001.txt 0002.txt 0003.txt 0004.txt 0005.txt 0006.txt 0007.txt 0008.txt 0009.txt

本篇發表於 未分類 並標籤為 。將永久鍊結加入書籤。

發表迴響

您的電子郵件位址並不會被公開。 必要欄位標記為 *

*

您可以使用這些 HTML 標籤與屬性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>