首先确定文件的原始字符编码:

$ file -bi test.txt

然后用 iconv 转换字符编码

$ iconv -f from-encoding -t to-encoding file > new-file

如果上面的步骤更改不成功,可以使用 vim 来更改文件的字符编码

先打开文件,然后设置文件的字符编码,在命令模式使用

set encoding=utf-8
set fileencoding=utf-8              (会改变正在编辑的文件的字符编码,千万别保存,一定要另存为, vim 的另存格式为 :w  new-file)

 

 

 

对于windows的编码,很多时候现实iso-8859,其实转码的时候应该使用 cp936:

iconv -f cp936 file_name -t UTF-8 -o file_name

对于多个文件,可以使用下面的命令来批量转:

find . -iname "*.h" | xargs -i sh -c "iconv -f cp936 {} -t UTF-8 -o {}"

查看有哪些文件是iso编码:

find . -iname "*" | xargs file | ack -i iso

 

以上是文件内容的转码,文件名的转码可以使用 convmv 这个工具,一般linux的中文文件名(采用utf8)可以在windows下正确的识别,因此只需要将windows的文件名在linux下转换出来。

 

相关文章:

  • 2021-08-14
  • 2022-12-23
  • 2022-02-02
  • 2021-11-28
  • 2021-11-19
  • 2022-12-23
  • 2021-06-08
猜你喜欢
  • 2021-12-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
  • 2022-03-04
  • 2022-01-17
相关资源
相似解决方案