當(dāng)前位置: 首頁(yè)IT技術(shù) → 批量修改指定目錄的文件名大小寫

批量修改指定目錄的文件名大小寫

更多

#!/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脫路簍攏盧脫驢嶄帽指么盧脣脪虜?shù)撁劼磰涿脛些鹵戮脡脙脳麓酶 # 賂帽驢錄脧攏盧脢脫小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 把這個(gè)目錄下面的全部替換為小寫了

sh -x 2.sh -u /root/test 把這個(gè)目錄下面的全部替換為大寫了

熱門評(píng)論
最新評(píng)論
發(fā)表評(píng)論 查看所有評(píng)論(0)
昵稱:
表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
字?jǐn)?shù): 0/500 (您的評(píng)論需要經(jīng)過(guò)審核才能顯示)