重新命名MacOS上某個目錄和子目錄中的所有檔案?

重新命名MacOS上某個目錄和子目錄中的所有檔案?

我正在嘗試回答這個問題的程式碼:

如何更改多個檔案的副檔名?

我試過這個:

# Rename all *.js to *.ts
for f in *.js; do 
    mv -- "$f" "${f%.js}.ts"
done

然而這會導致這樣的結果:

Oles-MacBook-Pro:src oleersoy$ ./rename.sh 
mv: rename *.js to *.ts: No such file or directory

我也嘗試過這個:

rename js ts *.js

結果是:

Bareword "js" not allowed while "strict subs" in use at (eval 2) line 1.

想法?

答案1

好的 - 在 SO 上找到了這個:

https://stackoverflow.com/questions/21985492/recursively-change-file-extensions-in-bash

這有效:

find . -name "*.t1" -exec rename 's/\.t1$/.t2/' '{}' +

相關內容