Changing upper-case filenames to lower-case

Liam R. E. Quin lee at sq.sq.com
Thu Dec 7 13:00:47 AEST 1989


In article <25747F32.4268 at ateng.com> chip at ateng.com (Chip Salzenberg) writes:
>According to merlyn at iwarp.intel.com (Randal Schwartz):
>>perl -e 'for$f(<*>){($_=$f)=~y/A-Z/a-z/;rename($f,$_)unless$f eq$_;}'

>I'd think that "<*>", which runs "/bin/sh echo", should be avoided.
>[much longer solution deleted]

Er, am I missing something?

for i in *
do
	mv $i `echo $i | tr '[A-Z]' '[a-z]'`
done

If you only want to move some of the files, change * to `pick *` (if you
have pick -- see ``The Unix Programming Environment'' (Kernighan & Pike)
for the source to pick if you don't)
If you also want to rename files that begin with a dot, replace the * with
`ls -a`, and use `find . -type f -print` to include files in subdirectories
and exclude subdirectories...

Is the issue really minimising the number of characters typed, getting the
most easily understood solution, or simply doing as much as possible in perl?
Do you get brownie points for the most cryptic perl one-liner?  0.5 :-)

Incidentally, one common way of getting lots of files in upper case on a
386 Unix system is by using some of the "dosget" or "doscp" programs.
In this case, it's worth writing a simple script that takes the output of
"dosdir" or "dosls" and generates a sequence of commands that copy the
files into lower case names.  Some versions of "dosget" have an option to
do this.

Lee
-- 
Liam R. Quin, Unixsys (UK) Ltd [note: not an employee of "sq" - a visitor!]
lee at sq.com (Whilst visiting Canada from England, until Christmas)
 -- I think I'm going to come out at last...
 -- What?  Admit you're not a fundamentalist Jew?  They'll *crucify* you!  :-)



More information about the Comp.unix.questions mailing list