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

How to solve the problem of File garbled in linux system

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

How to solve the file garbled in linux system? In view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

Linux file operations often encounter garbled problems, I searched the Internet for some solutions, I hope to be helpful to everyone.

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

: 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

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.

File coding conversion

1. Convert file encoding directly in Vim, such as converting a file to utf-8 format

: set fileencoding=utf-8

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

Iconv-f encoding-t encoding inputfile

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

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

Iconv-f gbk-t utf8 linux Common Command .txt > linux Common Command .txt.utf8

File name Encoding conversion:

When copying files from Linux to windows or from windows to Linux, sometimes the Chinese file name is garbled. The reason for this problem is that the Chinese coding of windows file name defaults to GBK, while the default file name encoding in Linux is UTF8, which leads to the problem of file name garbled due to inconsistent coding. To solve this problem, you need to transcode the file name.

A special tool convmv is provided in Linux for file name encoding conversion, which can convert file names from GBK to UTF-8 encoding or from UTF-8 to GBK.

First check to see if convmv is installed on your system, and use it if not:

Yum-y install convmv

Install.

Here's a look at the specific use of convmv:

Convmv-f Source Encoding-t New Encoding [option] File name

Common parameters:

-r Recursive processing subfolders

-notest actually operates, please note that by default, the file is not actually manipulated, but just an experiment.

-list displays all supported encodings

-unescap can do some escaping, such as turning% 20 into a space

For example, we have a file name encoded by utf8, which is converted to GBK encoding. The command is as follows:

Convmv-f UTF-8-t GBK-notest utf8 encoded file name

In this way, after the conversion, the "utf8-encoded file name" will be converted to GBK encoding (only the conversion of the file name encoding, the file content will not change)

This is the answer to the problem of how to solve the problem of document garbled in the linux system. I hope the above content can be of some help to everyone. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

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