Describes how to view the file encoding in Linux and convert the file encoding.

Source: Internet
Author: User

If you install the Linux operating system on a windows computer, you will find that the dual system also frequently encounters some problems. For example, if you operate files in windows in Linux, you may often encounter file Encoding Problems in Linux. In Windows, the default file format is GBK (gb2312), while Linux is generally a UTF-8. The following describes how to view the file encoding in Linux and convert the file encoding.

View File Encoding

You can view the file encoding in Linux in the following ways:

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

 
 
  1. :set fileencoding 

The file encoding format is displayed.

If you only want to view files in other encoding formats or want to solve the problem of using Vim to View File garbled characters, you can

~ /Add the following content to the vimrc file:

 
 
  1. set encoding=utf-8 fileencodings=ucs-bom,utf-8,cp936 

In this way, vim can automatically identify the file encoding can automatically identify the UTF-8 or GBK encoding files), in fact, according to the fileencodings provided by the encoding list to try, if not find the appropriate encoding, it is opened in latin-1 (ASCII) encoding.

 
 
  1. $ enca filename  
  2. filename: Universal transformation format 8 bits; UTF-8  
  3. CRLF line terminators 

Note that enca does not recognize some GBK-encoded files very well:

 
 
  1. Unrecognized encoding 

File encoding and conversion

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

 
 
  1. :set fileencoding=utf-8 

2. enconv conversion file encoding, for example, to convert a GBK encoded file into UTF-8 encoding, the operation is as follows

 
 
  1. enconv -L zh_CN -x UTF-8 filename 

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

 
 
  1. iconv -f encoding -t encoding inputfile 

For example, converting a UTF-8-encoded file into GBK Encoding

 
 
  1. iconv -f GBK -t UTF-8 file1 -o file2 

In this way, you can view the file encoding in Linux and convert the file encoding.

  1. Brief Introduction to februa Linux
  2. Detailed introduction to the use of Fedora Linux system files
  3. Describes the Linux GCC stability requirements.
  4. Learn more about Linux Network commands
  5. Install Linux firewall to ensure Linux security

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.