Article Title: easily complete file encoding in linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
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 directly viewed by adding an enca file name
# Enca-L zh_CN filename
Note: The enca does not recognize some GBK-encoded files very well. The unrecognized encoding will appear during the identification.
2. encoding of the conversion File
1) convert the file encoding directly in Vim. For example, convert a file to UTF-8 format.
: Sets 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 Available encoding for query
# 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 (linux/RPM/dag/redhat/el5/i386/"> 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