rename單次及批次修改檔案名稱

sudo apt install rename

練習,產生10個檔案

touch f{1..10}.txt
f1.txt  f10.txt  f2.txt  f3.txt  f4.txt  f5.txt  f6.txt  f7.txt  f8.txt  f9.txt

rename $1 $2 $3

  1. # $1: 要被取代的關鍵字

  2. # $2: 新的關鍵字

  3. # $3: 檔名符合這個規則的才取代

rename支持通配符

?可替代單個字符
*可替代多個字符
[charset]可替代charset集中的任意單個字符

rename f1 newf1 f1.txt

f10.txt f3.txt f5.txt f7.txt f9.txt f2.txt f4.txt f6.txt f8.txt newf1.txt

# 把檔案f2, ..., f9, f10 => 改成f002, ..., f009, f010

rename f f0 f?.txt

把所有.txt 檔案改成.html

rename .txt .html *.txt

rename .html .php f*.html

rename 'y/a-z/A-Z/' * 或 reanme f F *

把F變成F00

Last updated

Was this helpful?