Get the App
SLTechnology News&Howtos  ›  Development  › 

How to convert File Encoding under Linux

Shulou Source: shulou.com Published: 2022-06-01 18:33:32 10月05日 Update

This article mainly introduces the Linux file coding how to convert the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this Linux file coding how to convert the article will have a harvest, let's take a look.

This is because the default file format in Windows is GBK (gb2312), while Linux is generally UTF-8. So how to look at the encoding of the file in Linux and how to transcode the file?

1. Use VIM to view the file encoding

You can view file encodings directly in Vim

: set fileencoding

The file encoding format can be displayed.

2. Rewrite ~ / .vimrc file

If you just want to view files in other encoding formats or want to solve the problem of garbled viewing files with Vim, you can use the

Add the following to the ~ / .vimrc file

Set encoding=utf-8 fileencodings=ucs-bom,utf-8,cp936

In this way, you can let vim automatically identify file encodings (you can automatically identify UTF-8 or GBK encoded files), which is actually an attempt according to the coding list provided by fileencodings. If you do not find a suitable encoding, open it with latin-1 (ASCII) coding.

3. Transcoding with ICONV files

We use the iconv tool to convert the encoding of the file.

Iconv conversion. The command format of iconv is as follows:

Iconv-f encoding-t encoding inputfile

For example, convert a GBK-encoded file to UTF-8-encoded file

Iconv-f GBK-t UTF-8 file1-o file2

The meaning representation of the parameters in it

-f From some code

-t To some code

-o Export to file

4. Change the file encoding by saving notepad as

Open it with notepad under Windows and choose Save as. Just change the code.

This is the end of the article on "how to convert File Encoding under Linux". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to convert document coding under Linux". If you want to learn more knowledge, you are welcome to follow the industry information channel.

Tags: Coding file format UTF-8 content knowledge article automatic identification notepad appropriate random code value parameter just command that is tool meaning simple operation article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Linux Redmi Docker Xiaomi