linux下查看文件编码格式以及转换格式教程

嘿,Linux 下查看文件编码啊,简单,用 file 命令。
终端打开,命令行敲 file -i /path/your/file,这 /path/your/file 就是文件所在位置。
比如我有个 /opt/test.log,我就敲 file -i /opt/test.log。
它就会告诉你,这个文件是用的什么编码。

转编码啊,用 iconv。
先看 help,iconv --help,看看参数怎么用。
然后查查支持哪些编码,iconv -l,一长串,慢慢看。
转换呢,iconv -f 原编码 -t 目标编码 -o 输出文件名 --verbose 输入文件名,这么一串。
比如,我要把 /opt/test.log 从 iso-8 8 5 9 -1 转成 UTF-8 ,输出到 /opt/test1 .log,我就这样写 iconv -f iso-8 8 5 9 -1 -t UTF-8 -o /opt/test1 .log --verbose /opt/test.log。

转完啦,还得验证一下。
再用 file -i 查看一下,看看转换成功没。
比如,我再敲 file -i /opt/test1 .log,看输出是不是 UTF-8 就这么简单,Linux 下文件编码,没问题。

linux系统下文件夹和文件的字符集编码方式转换

Windows 文件夹名 GBK,浏览器 UTF-8 ,Linux 服务器 UTF-8 ,导致域名访问失败。

用 convmv 工具重编码文件夹名。

wget https://www.j3 e.de/linux/convmv/convmv-1 .1 5 .tar.gz make clean make install ./convmv -f GBK -t UTF-8 -r --notest Resources/
文件内容编码转换:
Vim 中: :set fileencoding=utf-8
Iconv 命令: iconv -f GBK -t UTF-8 file1 .txt -o file2 .txt
直接搞定。