Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
1  
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
add comment

3 Answers 3

up vote 4 down vote accepted

Try pyRenamer: http://www.webupd8.org/2010/01/pyrenamer-easy-mass-file-renaming-in.html

or similar: http://alternativeto.net/software/pyrenamer/?platform=linux&license=free

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
add comment

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
add comment

You can also use mmv.

sudo aptitude install mmv

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

share|improve this answer
add comment

Your Answer

 
discard

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.