如何在Linux中检查文件的字符编码 [英] How to check character encoding of a file in Linux

查看:333
本文介绍了如何在Linux中检查文件的字符编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些使用不同字符编码编码的文本文件,例如 ascii utf-8 big5 gb2312

I have some text files that're encoded by different character encodings, such as ascii, utf-8, big5, gb2312.

现在我想知道它们的准确字符编码,然后使用文本编辑器查看它们,否则,它们将显示乱码。

Now I want to know their accurate character encodings to view them with an text editor, otherwise, they will present garbled characters.

我在网上搜索并找到了个文件命令可以显示文件的字符编码,例如:

I searched online and found file command could display the character encoding of a file, like:

$ file -bi *
text/plain; charset=iso-8859-1
text/plain; charset=us-ascii
text/plain; charset=iso-8859-1
text/plain; charset=utf-8

不幸的是,使用 big5 gb2312 都存在 charset = iso-8859-1 ,因此我仍然无法区分。
是否有更好的方法来检查文本文件的字符编码?

Unfortunately, files encoded with big5 and gb2312 both present charset=iso-8859-1, so I still couldn't make a distinction. Is there a better way to check character encoding of a text file?

推荐答案

在某种程度上,@ ewcz的建议

To some extent, @ewcz's advice works.

$ uchardet *
big5.txt: BIG5
conf: ASCII
gb2312-windows.txt: GB18030
gb.txt: GB18030
test.java: UTF-8

enca -L chinese *
big5.txt: Traditional Chinese Industrial Standard; Big5
conf: 7bit ASCII characters
gb2312-windows.txt: Simplified Chinese National Standard; GB2312
  CRLF line terminators
gb.txt: Simplified Chinese National Standard; GB2312
test.java: Universal transformation format 8 bits; UTF-8

这篇关于如何在Linux中检查文件的字符编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆