In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to view file encodings in Linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
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
2. 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, files are not actually manipulated, but only experimented with.
-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)
Thank you for reading! This is the end of this article on "the method of viewing file coding in Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.