File character set encoding conversion in Linux

Source: Internet
Author: User


Linux file character set encoding conversion View file encoding file command file ip.txt View file encoding file command file ip.txtip.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 code www.2cto.com information:-l, -- list lists all known character set output control:-c ignores invalid characters-o from the output, -- output = FILE output FILE-s, -- silent close warning -- verbose prints progress information -?, -- Help provides the system's help list -- usage provides the simple usage information-V, -- version Printing program version example: iconv-f UTF-8-t gb2312 aaa.txt> examples file. 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 detailed parameters such as convmv-f GBK-t UTF-8 *. mp3 but this command will not 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. 3. The better command line tool, enca, not only intelligently identifies file encoding, but also supports batch conversion. Www.2cto.com 1. install $ sudo apt-get install enca2. check the current file encoding enca-L zh_CN ip.txt Simplified Chinese National Standard; GB2312Surrounded by/intermixed with non-text data3. the conversion command format is as follows $ enca-L current language-x destination encoding file name example to convert all files under the current directory to utf-8enca-L zh_CN- x UTF-8 * enca-L zh_CN file check file encoding enca-L zh_CN-x UTF-8 file convert file encoding to "UTF-8" encoding enca-L zh_CN-x UTF-8 <file1> file2 if you do not want to overwrite the original file, it's easy.

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.