|
[php]
#!/bin/bash
Usage ()
{
echo "Usage: `basename $0` dir"
}
if [ "$1" = "-h" -o "$1" = "--help" ];then
Usage
exit 0
fi
if [ $# -le 0 ];then
Usage
exit 1
fi
for file in `find $1 -maxdepth 1`;
do
if [ -d $file ]
then
echo "cancled"
else
iconv -f gb2312 -t utf-8 $file -o $file.ext
mv -f $file.ext $file
fi
done
[/php]
这个脚本的作用是把指定目录下的文件编码从gb2312转化为utf-8。
现在有个问题是我能通过什么命令知道一个文件的编码吗,要不然这个脚本遇到非gb码的文件就会出错。 |
|