我有以下文件:
boxScoreBaseball.html.php
boxScoreBasketball.html.php
boxScoreBowling.html.php
boxScoreCheer.html.php
boxScoreCrew.html.php
boxScoreCrossCountry.html.php
boxScoreEquestrian.html.php
boxScoreFieldHockey.html.php
boxScoreFootball.html.php
boxScoreGolf.html.php
boxScoreGymnastics.html.php
boxScoreHockey.html.php
boxScoreLacrosse.html.php
boxScoreRugby.html.php
boxScoreSkiing.html.php
boxScoreSoccer.html.php
boxScoreSoftball.html.php
boxScoreSwimming.html.php
boxScoreTennis.html.php
boxScoreTrack.html.php
boxScoreVolleyball.html.php
boxScoreWaterPolo.html.php
boxScoreWrestling.html.php
我想boxScore
從每個文件中取出該部分,例如,boxScoreBaseball.html.php
將變成baseball.html.php
.最簡單的方法是什麼?
答案1
可能只適用於 Bash:
for i in boxScore*; do mv $i ${i#boxScore}; done
我總是使用這個參考來進行快速而骯髒的 bash 內容:http://aurelio.net/shell/canivete/en/(請參閱第 4 節)。
答案2
答案3
您不能直接全部重新命名,必須使用 bash 腳本。也許這些連結對您有用:
答案4
執行這個小 shell 腳本:
for file in *; do echo "${file:8}" | sed -e 's/^\([A-Z]\)\(.*\)/\l\1\2/' | xargs mv "$file"; done
我們遍歷目前目錄中的每個檔案。首先,我們回顯不帶前 8 個字元的檔名。然後我們使用sed
將第一個字元轉換為小寫。搜尋sed
表達式的意思是“行首,組1:大寫字母,組2:其餘”,替換表達式的意思是“小寫匹配組1,然後追加組2”。最後一部分只是將舊檔案移動到轉換後的檔案名稱。