The method of converting file encoding under Linux system

Source: Internet
Author: User

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/1934062

The method of converting file encoding under Linux system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.