当前位置: 首页IT技术 → 批量修改指定目录的文件名大小写

批量修改指定目录的文件名大小写

更多

#!/bin/sh

# Usage: ./loworup.sh <-l | -u>

#

# 碌诙镁脨虏伪脴毛目录拢卢碌脷禄脨虏脦赂露篓-l禄貌#

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="."

#

# 脮赂枚篓脪5for 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

使用sh -x 2.sh -l /root/test 把这个目录下面的全部替换为小写了

sh -x 2.sh -u /root/test 把这个目录下面的全部替换为大写了

热门评论
最新评论
昵称:
表情: 高兴 可 汗 我不要 害羞 好 下下下 送花 屎 亲亲
字数: 0/500 (您的评论需要经过审核才能显示)