Replace text in folder names

Posted by dannyb on Stack Overflow See other posts from Stack Overflow or by dannyb
Published on 2010-04-19T01:38:46Z Indexed on 2010/04/19 1:43 UTC
Read the original article Hit count: 458

Filed under:
|
|
|
|

How can I replace the same text in folder names in linux?

Say I have "Photos_Jun", "Photos_July", "Photos_Aug", etc. whats the simplest way I can rename them like "Photos Jun", "Photos July", etc (basically I want to replace the underscore with a space " ". I have about 200 of these folders.

I was looking at solution: http://stackoverflow.com/questions/1836563/how-can-i-easily-bulk-rename-files-with-perl

It looks like what im looking for however, I dont know how to make a regular expression to match folders that are alphanumeric followed by a "_".

All files have non-numeric names, so I think [a-zA-Z] is the right way to start.

perl -e 'foreach $f (glob("File\\ Name*")) { $nf = $f; $nf =~ s/(\d+)$/sprintf("%03d",$1)/e; print `mv \"$f\" \"$nf\"`;}'

Thanks for any help!

© Stack Overflow or respective owner

Related posts about perl

Related posts about regex