Linux下打开windows中文文本乱码问题

Posted 焦距

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux下打开windows中文文本乱码问题相关的知识,希望对你有一定的参考价值。

1. 查看文件的编码方式:file命令

$ file test_file.txt
test_file.txt: ISO-8859 text, with very long lines

$ file train_model.py 
train_model.py: Python script, UTF-8 Unicode text executable

$ file 接口文档.docx 
接口文档.docx: Microsoft Word 2007+

但是file命令不太可靠, 一个gb2312编码的文件被判断为ISO-8859

 

2. 在gedit用指定的编码方式打开文件

打开gedit, 然后File => Open => 左下角的Character Encoding的右边有个下拉列表,选择Add or Remove... => 出现下图所示的设置界面,从左边列表中选择需要的编码方式添加到右边列表

 

然后在打开文件的时候选定需要的编码方式即可:

 

3. 转码: iconv命令

$ iconv -f gb2312 -t utf-8 test_file.txt -o test_file_utf8.txt
$ file test_file_utf8.txt
test_file_utf8.txt: UTF-8 Unicode text

 

iconv命令的用法具体如下:

$ iconv --help
Usage: iconv [OPTION...] [FILE...]
Convert encoding of given files from one encoding to another.

 Input/Output format specification:
  -f, --from-code=NAME       encoding of original text
  -t, --to-code=NAME         encoding for output

 Information:
  -l, --list                 list all known coded character sets

 Output control:
  -c                         omit invalid characters from output
  -o, --output=FILE          output file
  -s, --silent               suppress warnings
      --verbose              print progress information

  -?, --help                 Give this help list
      --usage                Give a short usage message
  -V, --version              Print program version

Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.

For bug reporting instructions, please see:
<https://bugs.launchpad.net/ubuntu/+source/glibc/+bugs>.

 

参考:https://www.cnblogs.com/longwaytogo/p/6308703.html

以上是关于Linux下打开windows中文文本乱码问题的主要内容,如果未能解决你的问题,请参考以下文章

解决“在UBUNTU下打开windows中创建的文本文件,中文显示乱码”的问题 。

windows下的txt文件传到Linux下中文乱码问题

Linux环境下shell输出的中文文件windows打开乱码问题处理

GVIM中文乱码问题(文本及菜单乱码)

Linux下windows中文文件乱码问题

Linux的office保存doc时出现中文乱码?