|
楼主 |
发表于 2003-4-16 23:37:02
|
显示全部楼层
哈哈,在伊甸园找到办法了。
20.11 如何将大写文件名转换为小写文件名
A: 小四
如果要处理整个目录树的话,可以这样
find -exec sh -c 'mv -f "$0" `echo "$0" | tr "[A-Z]" "[a-z]"` > /de
v/null 2>&1' {} \;
同理,将小写文件名转换为大写文件名如下
find -exec sh -c 'mv -f "$0" `echo "$0" | tr "[a-z]" "[A-Z]"` > /de
v/null 2>&1' {} \;
这个办法有待修正,处理多层目录名本身带有大写字母的情况,有问题。比如存在如
下目录的时候,./A/B/C/D.txt。
A: Potash@www.linuxforum.net 2002-02-05 18:58
--------------------------------------------------------------------------
#! /bin/sh
# Usage: ./loworup.sh <-l | -u>
#
# 第二形参必须是目录,第一形参指定-l或-u
#
if [ $# -ne 2 ] ; then
echo "Usage: ${0} <-l | -u> "
exit 1
fi
if [ ! -d ${2} -o "${1}" != "-l" -a "${1}" != "-u" ] ; then
echo "Usage: ${0} <-l | -u> "
exit 1
fi
exec 1>/dev/null 2>&1
dir=`dirname "${2}"`
cd ${dir}
if [ "${1}" = "-l" ] ; then
base=`basename "${2}" | tr "[A-Z]" "[a-z]"`
else
base=`basename "${2}" | tr "[a-z]" "[A-Z]"`
fi
mv -f "`basename ${2}`" "${base}"
for entry in `find ${base}`
do
before="."
#
# 这个办法依赖for in语法,用空格做分隔符,所以不能处理那些本身名字带空
# 格的目录项,属于小BUG
#
for after in `echo "${entry}" | sed -e 's,/, ,g'`
do
tmp_entry="${before}/${after}"
if [ "${1}" = "-l" ] ; then
before=`echo "${tmp_entry}" | tr "[A-Z]" "[a-z]"`
else
before=`echo "${tmp_entry}" | tr "[a-z]" "[A-Z]"`
fi
mv -f "${tmp_entry}" "${before}"
done
done |
|