On Fri, 22 May 1998, Simon Liddington wrote:
>Can anyone think of an easy way of changing the case of the names of a
>directory tree of files?

a bash shell script makes it easy:

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

Let's go over that a little bit. The for i in * construct will loop
over all files in that directory, and if we look at the line that does
all the work -- well firstly, it's a move command, of course, and the $i
is whatever filename that is being looked at, each time through the
loop.

Any stuff in backquotes `    ` end up being evaluated by a subshell, and
the result gets automagically "pasted" into the original command line.
So, we have the subexpression

   echo $i | tr [A-Z] [a-z]

which says to take the filename being looked at, and echo it into a
pipe, which then uses the Unix tr(1) command to turn whatever was sent
to the pipe into upper case. Then, the result of all that (an upper case
filename) gets pasted right into the original move command, and the net
result is a 'mv filename FILENAME'.

>Simon
>
>-- 
>------------------------------------------------------------------------
>| Simon Liddington                  |  Tel (home) : +44 (0)1703 346087 |
>| E-Mail : [EMAIL PROTECTED]   |  Tel (work) : +44 (0)1703 592422 |
>------------------------------------------------------------------------

--
------------------------------------------------------------------------
David E. Fox                 Tax              Thanks for letting me
[EMAIL PROTECTED]   the              change magnetic patterns
[EMAIL PROTECTED]      churches         on your hard disk.
-----------------------------------------------------------------------


-- 
  PLEASE read the Red Hat FAQ, Tips, Errata and the MAILING LIST ARCHIVES!
http://www.redhat.com/RedHat-FAQ /RedHat-Errata /RedHat-Tips /mailing-lists
         To unsubscribe: mail [EMAIL PROTECTED] with 
                       "unsubscribe" as the Subject.

Reply via email to