Linux中查看转换文件编码

在windows中,我一直使用Notepad++来查看转换编码,非常方便。在Linux中就需要使用命令行来完成了。

  1. 查看编码

    enca filename
    

    enca命令会推测文件的编码:

    > enca test.txt
    Simplified Chinese National Standard; GB2312
    CRLF line terminators

    现在我们知道文件是GB2312编码,CRLF结尾的。

  2. 转换编码

    iconv -f from_encode -t to_encode  sourcefile > destfile
    

    或者

    enconv -L zh_CN -x utf-8 filename
    

    前者需要制定源编码,输出转码后的内容到另外一个文件。

    后者不需要制定源编码,会直接修改源文件。

参考

发布了27 篇原创文章 · 获赞 13 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/mazhibinit/article/details/50240805
今日推荐