Character Set of file conversion in Linux

Source: Internet
Author: User

Character Set of file conversion in Linux

For some reason, we often encounter garbled characters on Linux servers, which are caused by inconsistent Character Set codes of clients, servers, and files, here we will explain how to convert the character set of a file.

You can run the following command to convert the character set of a file:

Iconv-f {character set before conversion}-t {character set after conversion} inputfile-o outputfile

Note: If the-o parameter is not specified, iconv prints the file only on the plane, but does not change the character set attribute of the original file.

For example, to convert a file from UTF-8 to gb18030, run the following command:

Iconv-f UTF-8-t gb18030 a.txt-o B .txt

Of course, you can also write data to a new file through redirection.

Iconv-f UTF-8-t gb18030 a.txt> B .txt

You can also use the ls-l command to generate a batch conversion File Script, as shown below:

Ls-lrt | awk '{print "iconv-f UTF-8-t gb18030" $9 "-o" $9 ". new "}'

You can also use the find command in combination with xargs or-exec for direct conversion.

This article permanently updates the link address:

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.