[geeks] Renaming en masse

Caleb Shay caleb at webninja.com
Mon Feb 24 16:08:55 CST 2003


Typo:

for x in `find . -type f`; do
  file=`basename $x`;
  lcfile=`basename $x | tr '[:upper:]' '[:lower:]'`;
  mv $x `echo $x | sed -e s/${file}/${lcfile}/`;
done

On Mon, 2003-02-24 at 17:06, Caleb Shay wrote:
> In bash:
> 
> for x in `find . -type f`; do
>   file=`basename $x`;
>   lcfile=`basename $x | tr '[:upper:]' '[:lower:]'`;
>   mv $x `echo $lcfile | sed -e s/${file}/${lcfile}/`;
> done
> 
> This is UNTESTED.  But it looks like it should work.
> 
> On Mon, 2003-02-24 at 16:48, Jonathan C. Patschke wrote:
> > I'm in the process of stashing a whole bunch of HTML files from CDs into
> > a server so that I can stop going nuts looking for documentation.  I've
> > run into a bit of a problem: Some of the CDs (especially the older ones)
> > don't have Rockridge encoding, so all the filenames are in upper case.
> > The author assumed that the files would be viewed on a PC using a
> > case-insensitive filesystem.
> > 
> > What's a good way to recursively rename an entire directory structure?
> > So far, I've done this:
> > 
> >   find . -depth -print > list.txt
> >   grep -v list.txt list.txt > list.new
> > 
> > That gets me a list of the files, removes "list.txt" from the list.  At
> > this point, I'd like to use "for" to iterate over the list of files, but
> > I can't seem to figure out what regexp would get the job done for me.
> > This:
> > 
> >   for i in `cat list.new`
> >         do mv $i `echo $i | tr '[:upper:]' '[:lower:]'`
> > 
> > won't work because it converts the entire path to lower-case, prior to
> > making the directories lower-case.  If there were a way that I could
> > apply 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwyz/' to
> > 's/\/[a-zA-Z0-9.-]*$/' on each line of list.new, I think that'd get it,
> > but I don't know enough sed to do that.
> > 
> > Is there perhaps a simple solution that I'm missing?
-- 
/*---------------------------------------------------------------------
Caleb Shay                                   "UNIX _IS_ user friendly.
Programmer/System Administrator              It's just particular about
Providence, RI                               who its friends are."
---------------------------------------------------------------------*/


More information about the geeks mailing list