1. Conversion of file content encoding using ICONV command
Usage: iconv [Options ...] [File ...]
The following options are available:
Input/output format specification:
-F,--from-code= name original text encoding
-T,--to-code= name output encoding
Information:
-L,--list enumeration of all known character sets
Output control:
-C ignores invalid characters from output
-O,--output=file output file
-S,--silent off warning
--verbose Printing Progress Information
-?,--Help gives a list of the systems
--usage gives a brief usage information
-V,--version print program version number
eg
Iconv-f gb2312-t utf-8 1.txt > 2.txt
This command reads 1.txt files, converts from gb2312 encoding to UTF-8 encoding, and its output is directed to a 2.txt file.
Note: The txt generated by the Windows WordPad is typically GB18030 encoded if the specified error is reported as follows:
ICONV: illegal input sequence at unknown 6071
2. file name encoding conversion
Because now with Linux, the original files in Windows are encoded with GBK. So copy to Linux is garbled, file content can be used iconv to convert but a lot of Chinese filename or garbled, find a can convert the file name Encoding command, is CONVMV.
CONVMV Command Detail parameters
eg
Convmv-f gbk-t UTF-8 *.mp3
However, this command does not convert directly, you can see the contrast before and after the conversion. If you want the conversion to be straight, add the parameter--notest
Convmv-f gbk-t UTF-8--notest *.mp3
The-f parameter indicates the encoding before the conversion, and-T is the converted encoding. Don't make a mistake about it. Otherwise, it may be garbled. There is one more parameter that is useful. IS-r This indicates that all subdirectories under the current directory are converted recursively.
* Need to install convmv-1.10-1.el5.noarch.rpm
3. Dummy command line tool eNCA
Installation:
Yum Install Enca-y
View current file encoding
Enca-l ZH_CN ip.txtsimplified Chinese national standard; gb2312surrounded by/intermixed with Non-text data
File format conversions:
Enca-l zh_cn-x Utf-8 *
Check the encoding of the files enca-l zh_cn file
Convert file encoding to "UTF-8" encoding
Enca-l zh_cn-x UTF-8 File
If you do not want to overwrite the original file, you can do so:
Enca-l zh_cn-x UTF-8 < file1 > File2
To view the encoding method:
A.
File filename
B. the file encoding can be viewed directly in Vim
: Set fileencoding
This article is from the "ZPP" blog, make sure to keep this source http://1439337369.blog.51cto.com/10270624/1934063
The method of converting file encoding under Linux system