[linux]用shell script將簡體檔名改成繁體檔名

其實這是舊東西了,之前發在我的天空,不過現在又修改了一下
繁體中文改用 BIG5HKSCS,可支援較多的繁體字

#!/bin/sh
r=0
function myhelp() {
echo Usage: gbtobig5 [-r] FILE
echo rename the gbcode filename to big5code filename
echo
echo -r, --recursive rename the contents of directories recursively
echo -h, --help show this help page
echo
echo
echo auther: kenshinn, taiwan
echo webpage: http://kenshinnn.blogspot.com
echo E-mail: kenshinnn@gmail.com
echo Msn: kenshinnkimo@msn.com
echo
echo updated on 2008/06/21
exit
}
function ren() {
i=$1
j=`echo $i|iconv -c -f utf8 -t gbk | iconv -c -f gbk -t big5hkscs | iconv -c -f big5hkscs -t utf8`
if [ $i = $j ] ; then return ; fi
echo `pwd`\/$i rename to `pwd`\/$j
mv $i $j
}
function dr() {
for i in $@ ; do
if [ -d $i ] && [ $r = 1 ] ; then cd $i ; dr * ; i=`basename \`pwd\`` ; cd .. ; fi
if [ -e $i ] ; then ren $i ; fi
done
}

IFS=""
if [ $# == 0 ] ; then myhelp ; return ; fi
for c in $@ ; do
if [ $c = -h ] || [ $c = --help ] ; then myhelp ; fi
if [ $c = -r ] || [ $c = --recursive ] ; then r=1 ; continue ; fi
done
dr $@

留言

這個網誌中的熱門文章

[Linux] 如何 hex 字串 與 文字互轉

記下 openssh 中 sftp的log

[linux]用指令來做音量控制