ubuntu下文件编码查看与转换

1.查看系统支持的字符集

cat /usr/share/i18n/SUPPORTED

如对中文会有以下一些显示

zh_CN.GB18030 GB18030
zh_CN.GBK GBK
zh_CN.UTF-8 UTF-8
zh_CN GB2312
 
(2.//一般第一步都支持不需要设置这一步
sudo vim /var/lib/locales/supported.d/local
说明:打开系统字符集配置文件,将第一步中支持的中文字符集添加进去
sudo dpkg-reconfigure --force locales强制更新设置。)
 
3.gedit 3.x ubuntu 11.0及以后版本ubuntu中文本编辑器Gedit 使用一个编码匹配列表,只有在这个列表中的编码才会进行匹配,这个列表没有的编码就显示为乱码,所以我们把汉字编码加入这个列表就行了。在终端下,运行 dconf-editor,然后在新的窗口中展开/org/gnome/gedit/preferences/encodings,这时右边第一项就是auto-detected或candidate-encodings(视gedit版本不同,新版为后者)。点击candidate-encodings的value,把'GB18030'或其他需要的字符集,写在UTF-8前面就行啦。注:不要在root模式下进去!sudo模式下进入设置这次键值对不会生效。
或在终端执行(使用此命令可以不用安装dconf-tools)
gsettings set org.gnome.gedit.preferences.encodings candidate-encodings "['GB18030','GB2312','GBK','BIG5','UTF-8','CURRENT','UTF-16']"
 
(4.安装dconf-tools
终端输入 sudo apt-get install dconf-tools 安装,然后输入sudo dconf-editor调出dconf-editor(如果用sudo命令进去之后添加不了内容可以尝试不用sudo,直接在终端输入dconf-editor调出dconf-editor)
 
5.查看文件编码使用file命令
file filename.txt
output: filename.txt UTF-8 Unicode text, with escape sequences
 
6.编码格式转换使用iconv命令
iiconv的命令格式如下:
iconv -f encoding -t encoding inputfile -o outputfile
比如将一个UTF-8 编码的文件转换成GBK编码
iconv -f UTF-8 -t GBK file1 -o file2
 
 
posted @ 2020-03-16 10:24  洪豆豆的记录  阅读(1995)  评论(0编辑  收藏  举报