On Fri, 22 May 1998, James C. Bevier wrote:

> > 
> > >>>>> "sl" == Simon Liddington <[EMAIL PROTECTED]> writes:
> > 
> >   sl> Can anyone think of an easy way of changing the case of the
> >   sl> names of a directory tree of files?
> > 
> > This comes up a lot as a question.  The answer involves using "tr".  A
> > full answer appears in the comp.unix.shell (or maybe comp.unix.misc)
> > FAQ, so I probably shouldn't reproduce it here.   It's reasonably
> > short.
> > 
> > 
> ---------------------try this----------------
> :
> # @(#) tolower v1.0
> #
> 
> if [ ! "$*" ]
> then
>    echo "Preparing to rename ALL files. OK to continue? (y/n) \c"
>    read OK
>    case $OK in
>       [yY])
>        LIST=`ls`
>          break
>          ;;
>       *)
>          echo "Usage : `basename $0` file [ file ... ]"
>          exit 1
>          ;;
>    esac
> else
>    LIST=$*
> fi
> 
> for NAME in $LIST
> do
>    NEW_NAME=`echo $NAME | tr "[A-Z]" "[a-z]"`
>    if [ "$NAME" != "$NEW_NAME" ]
>    then
>       echo "Renaming $NAME to $NEW_NAME"
>       mv ./$NAME ./$NEW_NAME
>    fi
> done
> 

That one isn't cryptic enough. Too easy to
understand.... ;-)  ;-)  ;-)

Put the following in a file called "fcase" and the
do a "chmod +x fcase" : 

--------------------CUT---------------------

#!/bin/bash
#

Usage () {
        echo "Usage: fcase u|l <files> ..."
        echo "   l = lowercase files"
        echo "   u = uppercase files"
        exit 1
}

[ $# -le 1 ] && Usage

C=$1
shift

[ ${C%[ul]} ] && Usage

for F in $*
do
        [ -e $F ] || {
                echo "file not found: $F"
                continue
        }
        D=${F%/*}
        N=${F##*/}
        case $C in
        u)      NN=$(echo $N | tr a-z A-Z) ;;
        l)      NN=$(echo $N | tr A-Z a-z) ;;
        esac
        [ ${N%$NN} ] || {
                echo "no change: $NN"
                continue
        }
        mv -v $D/{$N,$NN}
done

# End

--------------------CUT---------------------

--
John Darrah (u05192)    | Dept: N/C Programming
Giddens Industries      |
PO box 3190             | Ph: (206) 767-4212 #229
Everett  WA    98203    | Fx: (206) 764-9639


-- 
  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