Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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 several directories with the format of the year, month, and day followed by a description of the event. For example: "2012 05 26 - EventA", "2012 05 26 - EventB". What I would like to do is rename all these directories so that the spaces between the numbers in the date are replaced with dashes. Thus, "2012 05 26 - EventA" becomes "2012-05-26 - EventA". I know I can do this one folder at a time with the mv command, but is there a way to do this in a batch process with wildcards somehow?

share|improve this question
can you wait for 10 mins, i will write in c++ or bash – geoh May 26 '12 at 18:36
is there only that directorys? – geoh May 26 '12 at 18:37
There are 50 or so directories. That's just the format they're in. – Brian May 26 '12 at 18:42
is there only 2012 year files – geoh May 26 '12 at 18:47
There are several years accounted for. However, the answer below led me to a program that does the trick. Thank you, though! – Brian May 26 '12 at 19:01
up vote 5 down vote accepted

Try pyRenamer:

or similar:

share|improve this answer
That second link led me to GPRename, which seems to do the trick after some messing around. Thanks! – Brian May 26 '12 at 18:53
pyRenamer is the one I use, and is pretty powerful, but perhaps not as straightforward as it could be. Personally, I think it's worth learning, especially for music files, where you might want to normalize the file naming. It supports renaming using metadata for music and pictures. – Marty Fried May 26 '12 at 19:50

You can also use mmv.

sudo aptitude install mmv

#> mmv "201? * * - Event?" "201#1-#2-#3 - Event#4"

share|improve this answer

Use rename (with the -n option to test the changes):

rename 'm/(\d{4}) (\d{2}) (.*)/;$_="$1-$2-$3"' *

Rename is provided by perl so you may need to install it (don't know if it's part of the stock Ubuntu install):

sudo apt-get install perl
share|improve this answer

I wanted to rename multiple directories (folders, not files) and could not figure out if this is possible with pyRenamer. GPRename ( does the trick quite nicely though.

Ubuntu users should have GPRename in their reposiories and can run this command to install GPRename:

sudo apt-get install gprename

share|improve this answer

You cannot rename batch files using mv command. You need to write shell scripts, you can get the scripts by doing a google search or you can use the tools mentioned above.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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