在windows中,我一直使用Notepad++来查看转换编码,非常方便。在Linux中就需要使用命令行来完成了。
查看编码
enca filename
enca
命令会推测文件的编码:> enca test.txt Simplified Chinese National Standard; GB2312 CRLF line terminators
现在我们知道文件是GB2312编码,CRLF结尾的。
转换编码
iconv -f from_encode -t to_encode sourcefile > destfile
或者
enconv -L zh_CN -x utf-8 filename
前者需要制定源编码,输出转码后的内容到另外一个文件。
后者不需要制定源编码,会直接修改源文件。