Renaming multiple files.

MSameer's picture
Submitted by MSameer on Fri, 17/06/2005 - 10:17pm.
::

In the old days, I was using a for loop to rename multiple files.

Today I've discovered a new command: rename(1)

rename is not a traditional UNIX command but it comes with perl, And I guess you'll find a system without perl these days ;)

rename
Imaginr that you have some files with underscores in their names and you want to change the underscores to spaces.
In the old days I used to do:

for i in *; do echo mv $i "`echo $i | tr _ \  `"; done | bash

Now I can do:
rename 's/_/ /g' *
Note that s/_/ /g is a perl regular expression "perl regex"
for more information:
perldoc perlre