美文网首页
文件编码查看、转换

文件编码查看、转换

作者: 十毛tenmao | 来源:发表于2023-05-15 23:37 被阅读0次

文本文件都有编码格式,常见格式有UTF8、GBK、latin1等,因为编码不统一,所以在文件处理的时候经常会遇到编码导致的乱码问题

查看文件编码

  • file命令
$ file utf8_hello.txt
utf8_hello.txt: UTF-8 Unicode text

文件编码转换

  • 命令用法
iconv -f src_encoding -t target_encoding inputfile -o outputfile
  • 示例
# 把utf8编码的文件utf8_hello.txt转换为gbk编码的gbk_hello.txt
iconv -f utf-8 -t gbk utf8_hello.txt -o gbk_hello.txt

按照指定编码打开文件

  • vim
## 使用gbk编码打开文件file.txt
vim file.txt -c "e ++enc=gbk"
  • Sublime
File -> Reopen with Encoding

参考

相关文章

网友评论

      本文标题:文件编码查看、转换

      本文链接:https://www.haomeiwen.com/subject/lupvsdtx.html