1

I have the following files:

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

I would like to take the boxScore portion off of each file, so, for example, boxScoreBaseball.html.php would become baseball.html.php. What the easiest way to do this?

1
3

Probably only works with Bash:

for i in boxScore*; do mv $i ${i#boxScore}; done

I always use this reference for quick-and-dirty bash stuff: http://aurelio.net/shell/canivete/en/ (see section 4).

1
  • There's nothing particularly Basish here. Take care to use double quotes around file names, though.
    – tripleee
    May 25 '12 at 16:56
1

Another option is to use mmv (See this article for more examples).

For the given example:

mmv "boxScore*.html.php" "#1.html.php"
1

You can't directly rename all, you must use a bash script. Maybe these links will be usefull for you:

0

Run this little shell script:

for file in *; do echo "${file:8}" | sed -e 's/^\([A-Z]\)\(.*\)/\l\1\2/' | xargs mv "$file"; done

We iterate through every file in the current directory. First, we echo the file name without the first 8 characters. Then we use sed to convert the first character to lower case. The sed search expression means "beginning of line, group 1: an uppercase letter, group 2: the rest", and the replacement expression means "lowercase matching group 1, and then append group 2". The last part just moves the old file to the transformed file name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.