Linux encoding and encoding conversion, linux encoding conversion

Source: Internet
Author: User

Linux encoding and encoding conversion, linux encoding conversion

If you need to operate files in windows in Linux, you may frequently encounter file encoding conversion problems. 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 how to 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.
: 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:

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.


File encoding and conversion
1. Convert the file encoding directly in Vim. For example, convert a file to UTF-8 format.
: Sets fileencoding = UTF-8
2. iconv conversion. The iconv command format is as follows:
Iconv-f encoding-t encoding inputfile
For example, converting a UTF-8-encoded file into GBK Encoding
Iconv-f GBK-t UTF-8 file1-o file2

Iconv-f gbk-t utf8 commands are commonly used in Linux. txt> commonly used in Linux. txt. utf8

 
File Name encoding conversion:

When copying files from Linux to windows or from windows to Linux, Chinese file names may be garbled. This problem occurs because the Chinese encoding of windows file names is GBK by default, in Linux, the default file name encoding is UTF8. Because the encoding is inconsistent, the file name is garbled. To solve this problem, you need to transcode the file name.

In Linux, the tool convmv is designed to convert file names from GBK to UTF-8 encoding or from UTF-8 to GBK.

First, check whether convmv is installed on your system. If not, use:
Yum-y install convmv
Install.
 

The following describes how to use convmv:

Convmv-f Source Code-t new encoding [Option] File Name

Common parameters:
-R recursive processing of subfolders
-- Notest: the actual operation is not performed by default, but is only a test.
-- List displays all supported codes
-- Unescap can be used as an escape, for example, % 20 is converted into a space.
For example, we have a UTF-8 encoded file name and convert it to GBK encoding. The command is as follows:

Convmv-f UTF-8-t GBK -- notest utf8 encoded file name
In this way, the "utf8 encoded file name" will be converted to GBK encoding (only the file name encoding conversion will not change the file content)

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.