UP | HOME

中文解决方案

Table of Contents

1 编码转换

1.1 查看文件编码

enca 文件名
file 文件名

1.2 转换文件名由GBK为UTF8

sudo apt-get install convmv
convmv -r -f cp936 -t utf8 --notest --nosmart *

1.3 批量转换src目录下的所有文件内容由GBK到UTF8

find src -type d -exec mkdir -p utf8/{} \;
find src -type f -exec iconv -f GBK -t UTF-8 {} -o utf8/{} \;
mv utf8/* src
rm -fr utf8   

1.4 转换文件内容由GBK到UTF8

iconv -f gbk -t utf8 $i > newfile

1.5 批量转换文件内容由GBK到UTF8

for i in `find . *`; do if [ -f "$i" ]; then iconv -f gb2312 -t utf8 $i > "./converted/$i" fi ; done

1.6 转换 mp3 标签编码

sudo apt-get install python-mutagen
find . -iname '*.mp3' -execdir mid3iconv -e GBK {} \;

2 乱码解决

2.1 程序显示有些字大,有些小

sudo apt-get remove ttf-kochi-gothic ttf-kochi-mincho ttf-unfonts ttf-unfonts-core

2.2 PDF 文件乱码

sudo apt-get install xpdf-chinese-simplified xpdf-chinese-traditional poppler-data

2.3 Flash中文乱码

sudo gedit /etc/fonts/conf.d/49-sansserif.conf 
将倒数第四行 <string>sans-serif</string>
改为 <string>sans</string>
保存即可,重启firefox

2.4 unzip 中文文件名乱码

sudo apt-get install p7zip-full
export LANG=zh_CN.GBK  #临时在控制台修改环境为zh_CN.GBK,然后解压缩即可
7za e docs.zip

2.5 gedit中文乱码的解决

gconftool-2 --set /apps/gedit-2/preferences/encodings/auto_detected "[UTF-8,CURRENT,GB18030,BIG5,ISO-8859-15,UTF-16]" --type list --list-type string

2.6 解决vim中文编码问题,在~/.vimrc中加入

let &termencoding=&encoding
set fileencodings=utf-8,gbk,ucs-bom,cp936

Date: 2012-04-11 Wed

Author: Joseph Pan

Validate XHTML 1.0