And if you do not have perl installed, here is a non-perl solution. But there are ramifications to renaming files. If a process wants MYFILE, it will not find myfile. And you can have MYFILE and myfile in the same directory.
rename.sh downshift
will rename upper/mixed to lower case.
rename.sh upshift
will rename lower/mixed to upper case.
#!/bin/sh
if [ $# -ne 1 \
-o "$1" != upshift \
-a "$1" != downshift ]
then
echo '\nUsage: rename.sh [ upshift | downshift ]\n'
exit
fi
action=$1
for fn in *
do
if [ $action = upshift ] ; then
fn2=`echo $fn | tr -A "[:lower:]" "[:upper:]"`
else
fn2=`echo $fn | tr -A "[:upper:]" "[:lower:]"`
fi
if [ $fn = $fn2 -o $fn = rename.sh ] ; then
continue
fi
if [ -f $fn2 ] ; then
echo "Cannot $action $fn ($fn2 exists)"
else
echo "$action $fn ? [y|n] \c"
read ans
if [ "$ans" = y ] ; then
mv -i $fn $fn2
fi
fi
done
(end of script)
In case this script will be in the current directory, it has logic to prevent renaming itself, so if you call it something other than rename.sh, change that line of code.
As coded, the script asks for confirmation for each rename. If it gets a lowercase y, it will rename. If you do not want the confirmation logic, replace the last big if-statement with:
if [ -f $fn2 ] ; then
echo "Renaming $fn to $fn2 ... Cannot (target name exists)"
else
echo "Renaming $fn to $fn2 ..."
mv -i $fn $fn2
fi
The translate commands, instead of using :lower: and :upper: constructs, could also be coded:
fn2=`echo $fn | tr -A "[a-z]" "[A-Z]"`
fn2=`echo $fn | tr -A "[A-Z]" "[a-z]"`