Renaming multiple files en masse?

Mark Ovens mark at dogma.freebsd-uk.eu.org
Tue Apr 11 23:26:04 BST 2000


On Tue, Apr 11, 2000 at 10:01:00PM +0100, Paul Civati wrote:
> David Marsh at home <drmarsh at bigfoot.com> wrote:
> 
> > OK, this is a really dumb question (but hopefully an easy one)..
> > Could some kind person tell me how to rename multiple files en masse?
> > I'm not too much of a shell wizard, and was wondering how I would quickly
> > knock together a script to do this.
> > 
> > To give an example (well, actually _the_ specific example ;-) I need to
> > rename a directory full of .html files into .htm files (ugh, I know).
> 
> Using /bin/sh aka bourne shell:
> 
>   for i in *.html
>   do
>       mv $i `echo $i | sed 's/\.html$/.htm/'`
>   done
> 

or

#!/bin/sh

for i in `ls *.html`
do
	 mv $i `basename $i .html`.htm
done

Note that those are backticks, not single quotes.


> A bit hacky but it should do the job.
> 
> Basically loop through the *.html files, using mv to do the rename,
> use of backticks to construct the new file name.  The new file name
> being constructed by piping the current one through sed and doing
> a replace on the .html extension.
> 
> -Paul-
> 
> ------ FreeBSD UK User's Group  -  Mailing List ------
> http://listserver.uk.freebsd.org/mailman/listinfo/freebsd-users

-- 
        ...and on the eighth day God created UNIX
________________________________________________________________
      FreeBSD - The Power To Serve http://www.freebsd.org
      My Webpage http://ukug.uk.freebsd.org/~mark/
mailto:mark at ukug.uk.freebsd.org             http://www.radan.com





More information about the Ukfreebsd mailing list