Renaming multiple files en masse?

Jeremy Prior jez at netcraft.com
Wed Apr 12 10:06:25 BST 2000


On Wed, Apr 12, 2000 at 07:52:38AM +0100, Richard Smith wrote:
# > sorry couldn't resist..(as its only a suffix change..)
# > 
# > sh -c 'for fname in *.html ; do mv $fname ${fname%.html}.htm ; done'
# 
# sorry couldn't resist (as it's only a trailing letter deletion) :-) :-)
# 
# sh -c 'for f in *.html; do mv $f ${f%l}; done'
# 
# ------ FreeBSD UK User's Group  -  Mailing List ------
# http://listserver.uk.freebsd.org/mailman/listinfo/freebsd-users

These shell loops are all well and good for quick hacks, but for real
finesse, you need to do the job properly - ie perl! :-)

I've attached `move' - a program that allows you to apply perl
expressions to filenames.

Just put it somewhere in you path, (optionally) create a link to `copy'
(for the equivalent cp behaviour), and then the above would simply be.

  % move chop *.html

Although it's 50 lines long, only 38 are actual code, and 17 of those
are the usage message!

Apart from a (possibly gratuitously and unnecessary) upgrade to
perl5, this script has served me well for nearly 10 years...

jez
--
Jeremy Prior  <jez at netcraft.co.uk>  http://www.netcraft.co.uk/
 Netcraft Ltd,  1 Somerset Street,  Bath,  BA1 1TS,  England.
  Tel: +44-1225-404405 (direct-dial)   Fax: +44-1225-404401




More information about the Ukfreebsd mailing list