Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

migrated from stackoverflow.com May 25 '12 at 17:41

This question came from our site for professional and enthusiast programmers.

3  
See rename. – Shawn Chin May 25 '12 at 16:25
up vote 3 down vote accepted

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).

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

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

For the given example:

mmv "boxScore*.html.php" "#1.html.php"
share|improve this answer

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

share|improve this answer

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.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .