方法1、
//bug:当文件里有还有文件夹,这时,会把文件夹里最后一个文件名命名这个文件夹!
for uppercase in
`ls`
do
for lowercase in `ls $uppercase|tr [A-Z] [a-z]`
do
mv
$uppercase $lowercase 2>/dev/null
done
done
方法2、
//bug:
就是有点会报错,当有文件夹,和该sh在要改文件名大小写的目录内:
for file in `ls`
do
mv $file
`echo $file|tr "[A-Z]" "[a-z]"`
done
方法3、
#!/bin/sh
for
I in `ls` ;
do
C=$(echo $I|awk '{print toupper($I)}')
mv $I $C
done
方
法6、
//hen hao ,hen qiang da!
#!/bin/sh
############################################################
#
this script will change file name recursively with option
# -u:
locase to upcase
# -l: upcase to lowcase
############################################################
hint
() {
echo " Usage: $0 [-l|-u] DIR1 [DIR2 DIR3...]
-l to lowcase
-u
to upcase"
exit 1
}
if test $# -lt 2; then
echo "Too
few arguments."
hint
fi
while [ "$1" ]; do
case $1 in
-l)
ACTION="lo"
shift 1
;;
-u) ACTION="up"
shift 1
;;
*)
if test -d $1; then
DIR="$DIR $1"
else
echo "no such directory
--- $1"
hint
fi
shift
;;
esac
done
# echo
$ACTION
# echo $DIR
FOUND=`find $DIR | sort -r`
for
i in $FOUND; do
DN=`dirname $i`
BS=`basename $i`
loBS=`echo
$BS | tr '[A-Z]' '[a-z]'`
upBS=`echo $BS | tr '[a-z]' '[A-Z]'`
NAME1=$DN/$BS
if
[ "$ACTION" = "lo" ]; then
NAME2=$DN/$loBS
elif [ "$ACTION" =
"up" ]; then
NAME2=$DN/$upBS
fi
if [ "$NAME1" = "$NAME2" ];
then
echo "****: $NAME1 ---x--- $NAME2 identical!"
else
echo
"- renaming $NAME1 --> $NAME2"
mv $NAME1 $NAME2
fi
done
find
得到结果并不能直接拿来处理,因为它是自上而下的,而目录一旦改名,子目录就全抓瞎了。而经过排序后(先处理最深的目录,由里向外)就能用了。
阅读(871) | 评论(0) | 转发(0) |