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

转载于:https://www.cnblogs.com/bymo/p/8436776.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值