Generally speaking, the default file format in Windows is GBK (gb2312), while Linux is generally a UTF-8, so open the windows File in Linux will be garbled. In addition, sometimes the file must be encoded, such as converting Simplified Chinese to traditional Chinese.
Based on the above situation, this article describes how to view and convert the file encoding in linux.
1. view the file encoding.
1) You can directly view the file encoding in Vim.
: Set fileencoding to display the file encoding format.
2) enca view the file encoding
# Enca filename can be viewed directly by adding an enca file name # enca-L zh_CN filename Note: enca does not recognize some GBK-encoded files very well, and unrecognized encoding will appear during identification.
2. encoding of the conversion File
1) convert the file encoding directly in Vim. For example, convert a file to UTF-8 format.
:set fileencoding=utf-8
2) enconv conversion file encoding, such as to convert a GBK encoded file into UTF-8 encoding, such:
# Enconv-L zh_CN-x UTF-8 filename # enca-L zh_CN-x UTF-8 <file1> file2 does not overwrite the original file
3) iconv conversion. The iconv command format is as follows:
# Iconv-f encoding-t encoding inputfile # iconv-l query available encoding # for I in 'Find. /-name *. html '; do echo $ I; iconv-f gb2312-t big5 $ I-o/tmp/iconv. tmp; mv/tmp/iconv. tmp $ I; done
One of the batch conversion file encoding instances
3. File Name encoding conversion
When copying files between Linux and windows, the file name may contain garbled characters, because the Chinese encoding of the file name in Windows is GBK by default, and the default file name in Linux is UTF8. There is a tool in Linux, convmv, which can convert the file names between GBK and UTF.
Usage:
Convmv-f Source Code-t new encoding [option] filename
Install enca
Download the rpm package. Address http://rpmfind.net/linux/RPM/dag/redhat/el5/i386)
I downloaded: enca-1.10-1.el5.rf.i386.rpm and enca-devel-1.10-1.el5.rf.i386.rpm
Installation:
# rpm -ivh enca-1.10-1.el5.rf.i386.rpm # rpm -ivh enca-devel-1.10-1.el5.rf.i386.rpm