[GRLUG] Shell script needed

john-thomas richards jtr at jrichards.org
Tue Jul 3 15:57:37 EDT 2007


On Tue, Jul 03, 2007 at 03:08:00PM -0400, Marc Zuverink wrote:
> I am looking for a shell script to run on my /music.  It needs to
> replace all capital letters in all sub dirs of /music and replacing
> capital letters with lowercase replace all spaces with underscore in
> both the sub dirs and the enclosed files.
> 
> Help with this would really be appreciated!

Something like this?

#! /bin/sh

for filename in *                # Traverse all files in directory.
do
   fname=`basename $filename`
   n=`echo $fname | tr A-Z a-z`  # Change name to lowercase.
   if [ "$fname" != "$n" ]       # Rename only files not already
                                 # lowercase.
    then
    mv $fname $n
   fi  
done   

-- 
john-thomas
------
A multitude of laws in a country is like a great number of physicians, a
sign of weakness and malady.
Voltaire, philosopher (1694-1778)


More information about the grlug mailing list