다음 파일이 있습니다.
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
또 다른 옵션은 다음을 사용하는 것입니다 mmv
(참조더 많은 예를 보려면 이 문서를 참조하세요.).
주어진 예에서:
mmv "boxScore*.html.php" "#1.html.php"
답변3
모든 이름을 직접 바꿀 수는 없으며 bash 스크립트를 사용해야 합니다. 아마도 다음 링크가 도움이 될 것입니다.
답변4
이 작은 쉘 스크립트를 실행하십시오:
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 추가"를 의미합니다. 마지막 부분에서는 이전 파일을 변환된 파일 이름으로 이동합니다.