File character set encoding conversion in LINUX

Source: Internet
Author: User
Article Title: file character set encoding conversion 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.

View file encoding commands

File ip.txt

View file encoding commands

File ip.txt

Ip.txt: UTF-8 Unicode text, with escape sequences

1. Use the iconv command to encode and convert the File Content

The iconv command is used to convert the encoding of a specified file. By default, it is output to a standard output device, or an output file.

Usage: iconv [option...] [file...]

The following options are available:

Input/output format specifications:

-F, -- from-code = Name Original Text Encoding

-T, -- to-code = Name output Encoding

Information:

-L, -- list lists all known character sets

Output Control:

-C: Ignore invalid characters from the output

-O, -- output = FILE: output FILE

-S, -- silent close warning

-- Verbose prints the progress information

-?, -- Help: Provides the system's help list

-- Usage provides brief usage information

-V, -- version print the program version number

Example:

Iconv-f UTF-8-t gb2312 aaa.txt> bbb.txt

This command reads the aaa.txt file and converts it from the 8th to the gb2312th file, and the output is directed to the bbb.txt file.

Ii. File Name encoding conversion

Because now linux is used, all files in windows are encoded with GBK. Therefore, copying to linux is garbled, and the file content can be converted using iconv. However, many Chinese file names are still garbled. Find a command that can convert the file name encoding, that is, convmv.

Convmv Command Parameters

For example

Convmv-f GBK-t UTF-8 *. mp3

However, this command does not convert directly. You can see the comparison before and after conversion. If you want to add the parameter -- notest to the direct conversion

Convmv-f GBK-t UTF-8 -- notest *. mp3

-F indicates the encoding before conversion, and-t indicates the encoding after conversion. Do not make a mistake. Otherwise it may be garbled. Another parameter is useful. -R indicates recursively converting all subdirectories in the current directory.

3. The better command line tool, enca, not only intelligently identifies file encoding, but also supports batch conversion.

1. Install

$ Sudo apt-get install enca

2. view the current file encoding

Enca-L zh_CN ip.txt

Simplified Chinese National Standard; GB2312

Surrounded by/intermixed with non-text data

3. Conversion

Command Format:

$ Enca-L current language-x destination encoded file name

For example, convert all files in the current directory to UTF-8.

Enca-L zh_CN-x UTF-8 *

Enca-L zh_CN file check file encoding

Enca-L zh_CN-x UTF-8 file to convert file encoding to "UTF-8" Encoding

Enca-L zh_CN-x UTF-8 <file1> file2 can do this if you don't want to overwrite the original file.

Original address http://www.netbei.com/2009/1120/17865.html

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.