linux iconv字符编码批处理方式转换

来源:互联网 发布:画坐标图软件 编辑:程序博客网 时间:2024/05/29 14:23

查看编码:

$ find ./ -type f -exec file -i {} \; > /tmp/a

file命令查看文件编码
file -i filename

查询是否存在已经是utf-8编码的文件:

grep “charset=utf-8” /tmp/a

转换

find ./ -type d -exec mkdir -p utf {} \;
find . -type f -exec iconv -f iso-8859-1 -t UTF-8 {} -o ./utf/{} \;

file -i 查看的编码是“charset=iso-8859-1“,可是中文出现乱码,改成gb2312就好似没有问题了。也就是执行这个命令“find . -type f -exec iconv -f gb2312 -t UTF-8 {} -o ./utf/{} \;“

iconv格式:iconv -f from-encoding -t to-encoding inputfile -o outputfile

参考:http://blog.csdn.net/philosophyatmath/article/details/50496556

1 0
原创粉丝点击