Viewing file encoding formats and file encoding conversion in Linux

Source: Internet
Author: User
In Linux, you can view the file encoding format and file 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 format and file encoding conversion in Linux. 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. You can view the file encoding in Linux in the following ways: 1. you can view the file encoding directly in Vim: set fileencoding to display the file encoding format. 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, 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. 2. enca (if this command is not installed in your system, you can use sudo yum install-y enca to install it) to view the file code $ enca filenamefilename: Universal transformation format 8 bits; UTF-8CRLF line terminators need to note that the enca is not very good on some GBK encoding files, the identification will appear: Unrecognized encoding file encoding conversion 1. convert the file encoding directly in Vim. for example, convert a file to UTF-8: 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 enconv-L zh_CN-x UTF-8 filename 3. iconv Conversion. The iconv command format is as follows: ic Onv-f encoding-t encoding inputfile For example converting a UTF-8-encoded file into GBK-encoded iconv-f GBK-t UTF-8 file1-o file2 Linux file name encoding conversion copying files from Linux to windows or copy files from windows to Linux, sometimes Chinese file names are garbled. The cause of this problem is that the Chinese encoding of windows file names is GBK by default, while that of Linux is UTF8 by default, because the encoding is inconsistent, the file name is garbled. to solve this problem, you need to transcode the file name. In Linux, a tool named convmv is provided to convert file name encoding 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. Next, let's take a look at the specific usage of convmv: convmv-f source code-t new encoding [option] common parameters of File name:-r recursive processing sub-file folder -- notest for true operations, note that by default, files are not actually operated, but only for testing. -- List shows all supported codes -- unescap can be used for escape. for example, % 20 is converted into a space. for example, we have an utf8 encoded file name and converted it into GBK encoding. the command is as follows: convmv-f UTF-8-t GBK -- notest utf8 encoded file name after this conversion "utf8 encoded file name" will be converted to GBK encoding (only the conversion of file name encoding, file content will not change ). Note: Do not use this command in the NTFS and FAT file systems. otherwise, unexpected results may occur. if you want to correctly display the NTFS and FAT file names in Linux, you can solve this problem by using the mount parameter. for details, refer to the man manual.
Related Article

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.