主机参考:VPS测评参考推荐/专注分享VPS服务器优惠信息!若您是商家可以在本站进行投稿,查看详情!此外我们还提供软文收录、PayPal代付、广告赞助等服务,查看详情! |
我们发布的部分优惠活动文章可能存在时效性,购买时建议在本站搜索商家名称可查看相关文章充分了解该商家!若非中文页面可使用Edge浏览器同步翻译!PayPal代付/收录合作 |
linux中字符乱码应该如何解决?很多人都不太了解,今天小编为了让大家更加了解linux中字符乱码的解决方案,所以给大家总结了以下内容,一起往下看吧。
How to solve the character disorder in Linux? Many people don't know much about it. Today, in order to let you know more about the solution of character scrambling in Linux, Xiaobian summarized the following content for you, let's look down together.
远程登录linux服务器用vim在终端下编辑查看文件经常会遇见各种中文乱码问题。
Remote login Linux server using VIM to edit and view files under the terminal will often encounter a variety of Chinese code problems.
做如下设置可基本解决vim中文乱码问题
The following settings can basically solve the problem of vim Chinese scrambling
首先查看系统对中文的支持
First check the system's support for Chinese
locale -a | grep zh_CN
locale -a | grep zh_CN
输出样例如下
An exle of the output is as follows
zh_CN.gbk
Zh_CN.gbk
zh_CN.utf8
Zh_CN.utf8
vim 只能正确识别列表中的中文编码文件,如需识别其他编码类型的中文文件,则需要做系统升级
VIM can only correctly identify the Chinese code files in the list. If it needs to identify other types of Chinese code files, it needs to upgrade the system
vi ~/.bash_profile
vi ~/.bash_profile
文件末尾添加
Add at end of file
export LANG="zh_CN.UTF-8"
export LANG="zh_CN.UTF-8"
export LC_ALL="zh_CN.UTF-8"
export LC_ALL="zh_CN.UTF-8"
vim与编码相关的参数:
VIM coding related parameters:
1、eencoding,用于配置打开文件和保存文件的编码,但只能有一个值,只适合少数文件都是同种编码的环境,所以一般不使用
1. Eencoding is used to configure the encoding for opening and saving files, but it can only have one value. It is only suitable for a few files in the same encoding environment, so it is generally not used
2、fileencodings, 从名字上看就知道是fileencoding的增强版,可以配置多种不同的编码,常见的配置为,配置好之后,列表中的文本编码只要合法,都能被vim正确 的读取,建议配置:set fileencodings=utf-bom,utf-8,gbk,gb2312,gb18030,cp936,latin1
2. Fileencodings, as you can see from the name, is an enhanced version of fileencodings, which can be configured with many different codes. The common configuration is that after configuration, the text codes in the list can be read correctly by VIM as long as they are legal. It is recommended to configure: set fileencodings = UTF BOM, UTF-8, GBK, GB2312, GB18030, cp936, Latin1
3、encoding,vim内部编码,vim读取文件之后,但并不以读取文件的编码来处理,而是会转换成内部编码的格式,这个编码一般与操作系统相关,linux下utf-8居多,中文windows下则是gdk,建议配置:set encoding=utf-8
3. Encoding, VIM internal encoding. After VIM reads the file, it is not processed by the encoding of the read file, but will be converted to the format of internal encoding. This encoding is generally related to the operating system. UTF-8 is the majority in Linux, GDk in Chinese windows. It is recommended to configure: Set encoding = UTF-8
4、termencoding,vim输出的编码,输出指输出到操作系统或命令终端等,默认与操作系统的语言编码一致,如果使用linux命令终端,建议终端和linux系统配置相同的编码,然后配置相同的termencoding,否则顾全了vim就顾不上shell,不过如果shell不存在中文名文件,则配置终端和 termencoding一致即可,对于windows,能自动的识别gbk和utf-8,不用特殊配置,建议配置:set termencoding=utf-8
4. Termencoding, the encoding of vim output, output refers to output to the operating system or command terminal, which is the same as the language encoding of the operating system by default. If Linux command terminal is used, it is recommended that the terminal and Linux system configure the same encoding, and then configure the same termencoding, otherwise VIM will ignore the shell, but if there is no Chinese name file in the shell, the configuration is final For windows, it can automatically identify GBK and UTF-8 without special configuration. The recommended configuration is set termencoding = UTF-8
5、fileformats,用于区分操作系统,主要是回车rn的区别,建议配置:set fileformats=unix,dos
5. Fileformats, used to distinguish operating systems, mainly the difference of carriage return. It is recommended to configure: set fileformats = UNIX, DOS
常见的乱码有以下几种情形:
There are several common cases of garbled Code:
(1)将windows环境下的文件rz到linux下时文件出现乱码
(1) When RZ file under Windows environment is transferred to Linux, the file appears garbled
解决方案:
Solution:
1、在rz之前使用notepad++将文件格式转化为UTF-8无BOM格式或者ANSI编码格式;
1. Before RZ, use Notepad + + to convert the file format to UTF-8 format without BOM or ANSI encoding format;
2、set encoding=utf-8;
2、set encoding=utf-8;
(2)secureCRT或者xterm2编辑环境中出现乱码,只需在会话选项中调节字符编码为GB2312或者UTF-8
(2) in the secureCRT or xterm2 editing environment, the encoding is only GB2312 or UTF-8 in the session options.
(3)当对日志文件进行vim编辑时出现乱码,大多数情况下是因为日志文件的格式为GB2312。
(3) When the log file is VIM edited, there is garbled code, mostly because the format of the log file is GB2312.
解决方案:1.set encoding=GB2312;2如果方案1不起作用的话,调整secureCRT或者xterm2的编辑环境为GB2312
Solution: 1. Set encoding = GB2312; 2 if scheme 1 does not work, adjust the editing environment of SecureCRT or xterm2 to GB2312
(4)wget下载文件名乱码
(4) WGet download file name garbled
解决方案:一般情况下加上–restrict-file-names=nocontrol,例如wget --restrict-file-names=nocontrol -m www.xxx.com/
Solution: in general, add - restrict file names = nocontrol, such as WGet -- restrict file names = nocontrol - M www.xxx.com/
(5)cat文件正常,vim文件不正常
(5) Cat file is normal, VIM file is abnormal
解决方案:直接写入/etc/vim/vimrc ,最后一行加上
Solution: write directly to / etc / VIM / vimrc, and add the last line
set fileencodings=gb2312,utf-8
set fileencodings=gb2312,utf-8
set fileencoding=gb2312
set fileencoding=gb2312
set termencoding=utf-8
set termencoding=utf-8
关于linux中字符乱码应该如何解决就分享到这里了,当然并不止以上和大家分析的办法,不过小编可以保证其准确性是绝对没问题的。希望以上内容可以对大家有一定的参考价值,可以学以致用。如果喜欢本篇文章,不妨把它分享出去让更多的人看到。
How to solve the character disorder in Linux will be shared here. Of course, it's not only the above analysis method, but also the small code can ensure its accuracy is absolutely no problem. Hope that the above content can have a certain reference value for you, can learn to apply. If you like this article, you can share it for more people to see.
--------------------------------------------------------------
主机参考,收集国内外VPS,VPS测评,主机测评,云服务器,虚拟主机,独立服务器,国内外服务器,高性价比建站主机相关优惠信息@zhujicankao.com
详细介绍和测评国外VPS主机,云服务器,国外服务器,国外主机的相关优惠信息,商家背景,网络带宽等等,也是目前国内最好的主机云服务器VPS参考测评资讯优惠信息分享平台
这几篇文章你可能也喜欢:
- 华纳云,香港特价CN2云服务器特价3折低至240/年,精选CN2/站群/大带宽/高防服务,E5系列服务器搭配50M CN2专线,续费同享优惠
- SpinServers,国外高性能高配独立服务器特价优惠低至$179/月,美国圣何塞/达拉斯机房,2*E5-2696 v3处理器/256G内存/10Gbps超大带宽
- ToToTel- 真正的黑色星期五活动。 始终先打开服务器。 满意后再付款! 支持PAYPAL/支付宝
- RackNerd:15美元/年/1核@Ryzen 7950X/512MB内存/6GB NVMe空间/400GB流量/1Gbps端口/KVM/洛杉矶/圣何塞/芝加哥/纽约/达拉斯等。
- CSTserver 宣传香港/美国优化线路云服务器为 2.2 美元/月,裸机为 19.9 美元/月,高防御为 30 美元/月,10G 高带宽为 39 美元/月,站点组为 105 美元/月。
本文由主机参考刊发,转载请注明:linux中字符乱码应该如何解决? https://zhujicankao.com/14183.html
评论前必须登录!
注册