Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Introduction to the method of viewing and converting File Encoding under Linux system

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains the "Linux system file coding view and conversion method introduction", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "Linux system file coding view and conversion method introduction"!

If you need to manipulate files under windows in Linux, you may often encounter problems with file encoding conversion. The default file format in Windows is GBK (gb2312), while Linux is generally UTF-8. Here's how to view the encoding of a file in Linux and how to transcode a file.

View file encodings

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

(1)。 You can view file encodings directly in Vim

The code is as follows:

: set fileencoding

The file encoding format can be displayed.

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

The code is as follows:

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.

(2)。 Enca (if you do not have this command installed on your system, you can install it with sudo yum install-y enca) to view the file encodings

The code is as follows:

$enca filename

Filename: Universal transformation format 8 bits; UTF-8

CRLF line terminators

It is important to note that enca does not recognize some GBK-encoded files very well, and it will appear during recognition:

Unrecognized encoding

File coding conversion

Because now using linux, the original files in windows are encoded in GBK. So copy to linux is garbled, file content can be converted with iconv, but a lot of Chinese file names are still garbled, find a command that can convert file name coding, that is, convmv.

Detailed parameters of the convmv command such as

The code is as follows:

Convmv-f GBK-t UTF-8 * .mp3

However, this command will not convert directly, you can see the comparison before and after the conversion. If you want a direct conversion, you need to add a parameter-- notest.

The code is as follows:

Convmv-f GBK-t UTF-8-- notest * .mp3

The-f parameter indicates the pre-conversion code, and-t is the converted code. Make no mistake about this. Otherwise, it may still be garbled. There is another parameter that is useful. This means to recursively convert all subdirectories under the current directory.

* convmv-1.10-1.el5.noarch.rpm needs to be installed

A better stupid command line tool, enca, which not only intelligently recognizes the encoding of files, but also supports batch conversion.

(1)。 Installation

The code is as follows:

$sudo apt-get install enca

(2)。 View current file encoding

The code is as follows:

Enca-L zh_CN ip.txt

Simplified Chinese National Standard; GB2312 Surrounded by/intermixed with non-text data

(3)。 The format of the conversion command is as follows

$enca-L current language-x target encoding file name

For example, to convert all files in the current directory to utf-8

The code is as follows:

Enca-L zh_CN-x utf-8 *

Check the encoding of the file

The code is as follows:

Enca-L zh_CN file

Convert file encoding to "UTF-8" encoding

The code is as follows:

Enca-L zh_CN-x UTF-8 file

You can do this if you don't want to overwrite the original file.

The code is as follows:

Enca-L zh_CN-x UTF-8

< file1 >

File2

Thank you for your reading, the above is the "introduction of file coding viewing and conversion methods under the Linux system", after the study of this article, I believe you have a deeper understanding of the problem of viewing and conversion methods of file coding under the Linux system, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report