例如,我想將當前目錄中的所有檔案與 匹配.template,制作副本并將其重命名為.fruit.
前
apple.template
pineapple.template
orange.template
book.ex
desk.tx
后
apple.template <-- old
pineapple.template <-- old
orange.template <-- old
book.ex <-- old
desk.ex <-- old
apple.fruit <-- new
pineapple.fruit <-- new
orange.fruit <-- new
uj5u.com熱心網友回復:
你可以用一個簡單的回圈來解決這個問題:
for i in *.template
do
cp "$i" "${i%.template}.fruit"
done
uj5u.com熱心網友回復:
ls -1q *template | sed -s 's/.template$//' | xargs -I {} cp "{}.template" "{}.fruit"
您獲取所有以 .template 結尾的檔案,獲取它們的基本名稱(不帶擴展名),然后將檔案復制到具有新擴展名的檔案中。
uj5u.com熱心網友回復:
while read FILE
do
cp "$FILE" "${FILE%.*}".fruit
done < <(find . -maxdepth 1 -type f -name "*.template")
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/478105.html
