6

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?

  • 1
    can you wait for 10 mins, i will write in c++ or bash – hingev May 26 '12 at 18:36
  • is there only that directorys? – hingev 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 – hingev 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
5

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

  • 1
    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
1

You can also use mmv.

sudo aptitude install mmv

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

0

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
0

I wanted to rename multiple directories (folders, not files) and could not figure out if this is possible with pyRenamer. GPRename (http://gprename.sourceforge.net/) 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

-1

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.

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.