Convert windows file encoding in linux

Source: Internet
Author: User
1. use the iconv command to encode and convert the file content. 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...

 

1. use the iconv command to encode and convert the file content

 

 

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 gb2312-t UTF-8 aaa.txt> bbb.txt

This command reads the aaa.txt file and converts it from gb2312 to utf-8, and the output is directed to the bbb.txt file. Note: In windows, the txt generated by the WordPad is generally gb18030 encoded. If an error is specified, the following error is returned: iconv: the input sequence at unknown 6071 is invalid.

 

 

II. file name encoding and conversion because linux is used now, all files in windows are encoded using 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 but this command won't convert directly, you can see the comparison before and after conversion. If you want a straight conversion to add the parameter -- notestconvmv-f GBK-t UTF-8 -- notest *. the mp3-f parameter is the encoding before the conversion, and-t is the encoding after the 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. * Need to install convmv-1.10-1.el5.noarch.rpm 3, better silly command line tool enca, it can not only intelligently identify file encoding, but also support 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.

 

From: tonychiu.blog.51cto.com

Related Article

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.