File encoding in linux

Source: Internet
Author: User

Generally speaking, the default file format in Windows is GBK (gb2312), while Linux is generally a UTF-8, so open the windows File in Linux will be garbled. In addition, sometimes the file must be encoded, such as converting Simplified Chinese to traditional Chinese.

Based on the above situation, this article describes how to view and convert the file encoding in linux.

1. view the file encoding.

1) You can directly view the file encoding in Vim.

: Set fileencoding to display the file encoding format.

2) enca view the file encoding

# Enca filename can be viewed directly by adding an enca file name # enca-L zh_CN filename Note: enca does not recognize some GBK-encoded files very well, and unrecognized encoding will appear during identification.

2. encoding of the conversion File

1) convert the file encoding directly in Vim. For example, convert a file to UTF-8 format.

    :set fileencoding=utf-8

2) enconv conversion file encoding, such as to convert a GBK encoded file into UTF-8 encoding, such:

# Enconv-L zh_CN-x UTF-8 filename # enca-L zh_CN-x UTF-8 <file1> file2 does not overwrite the original file

3) iconv conversion. The iconv command format is as follows:

# Iconv-f encoding-t encoding inputfile # iconv-l query available encoding # for I in 'Find. /-name *. html '; do echo $ I; iconv-f gb2312-t big5 $ I-o/tmp/iconv. tmp; mv/tmp/iconv. tmp $ I; done

One of the batch conversion file encoding instances

3. File Name encoding conversion

When copying files between Linux and windows, the file name may contain garbled characters, because the Chinese encoding of the file name in Windows is GBK by default, and the default file name in Linux is UTF8. There is a tool in Linux, convmv, which can convert the file names between GBK and UTF.

Usage:

Convmv-f Source Code-t new encoding [option] filename

Install enca

Download the rpm package. Address http://rpmfind.net/linux/RPM/dag/redhat/el5/i386)
I downloaded: enca-1.10-1.el5.rf.i386.rpm and enca-devel-1.10-1.el5.rf.i386.rpm

Installation:

   # rpm -ivh enca-1.10-1.el5.rf.i386.rpm   # rpm -ivh  enca-devel-1.10-1.el5.rf.i386.rpm

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.