The "rename" command lets you rename lots of files according to a pattern. I wish I'd known about this command earlier.
Synopsis
rename from to file...Description
rename will rename the specified files by replacing the first occurrence of from in their name by to.For example, given the files blah1, ..., blah9, blah10, ..., blah278, the commands
rename blah blah0 blah?
rename blah blah0 blah??will turn them into blah001, ..., blah009, blah010, ..., blah278. And
rename .htm .html *.htmwill fix the extension of your html files.
Posted on January 22, 2004 08:55 PM
More programming articles
Bah... Perl "utilities" don't count as "commands". I say roll your own, why let someone else have all the pleasure of writing something like this when you can do it yourself ;-)
Posted by: Michael Tucker at January 22, 2004 10:19 PMHeh, that would have been nice. I, too, wrote my own regex variant of this command a while back.
Posted by: Luke Palmer at January 23, 2004 05:22 AMWow, I've been unixing for 9 years and have always done that using a bash "for" loop and ${name/from/to}. Never knew there was a precanned version. Cool.
Posted by: Andrew Birkett at January 23, 2004 12:46 PMThanks, I didn't know about ${name/from/to} before either.
Posted by: kim at January 23, 2004 01:52 PMA year or so ago I had a similar rename situation. I even implemented a bunch of renaming scripts in different languages (elisp, perl, python). Someone then pointed out rename to me as well. Anyway, if you're interested in how the same simple function is implemented in different languages here's the result of my "research". http://www.zanthan.com/itymbi/archives/000799.html#000799 and
http://www.zanthan.com/itymbi/archives/000802.html#000802