XShell连接CentOS 7.2显示中文乱码问题的解决方法

背景

使用U盘往Windows主机、Linux主机传文件还是经常的事,但有时候文件名有中文,

传到Linux机器会有乱码,选择起来也很麻烦,最近刚好遇到,写下解决方法。

环境

Linux

[root@min-base ~]# cat /etc/redhat-release
CentOS Linux release 7.2. (Core)
[root@min-base ~]# echo $LANG
en_US.UTF-
[root@min-base ~]#

Windows XShell

XShell连接CentOS 7.2显示中文乱码问题的解决方法

问题

txt文件是用Xftp直接从Windows上拖过来的,在Linux机上显示乱码了。

[root@min-base ~]# ll
total
-rw-------. root root Dec : anaconda-ks.cfg
drwxr-xr-x. root root Dec : cmake-3.7.-Linux-x86_64
-rw-r--r--. root root Dec : cmake-3.7.-Linux-x86_64.tar.gz
drwxr-xr-x. root root Dec : llvm-src
-rw-r--r--. root root Jan : llvm-src.tar.gz
drwxr-xr-x. Aug vim74
-rw-r--r--. root root Dec : vim-7.4.tar.bz2
-rw-r--r--. root root Jan : ??????ϰregexp.txt
[root@min-base ~]#

解决

一般这种问题是文件的编码字符集、Shell编码字符集、XShell编码字符集不匹配,设置匹配就可以了。

临时办法

1)简体中文的Windows一般使用GB字符集,这里将XShell设置为GBK

XShell连接CentOS 7.2显示中文乱码问题的解决方法

2)

Linux主机

[root@min-base ~]# export LANG=zh_CN.gbk

再试,就可以正常显示中文了。

[root@min-base ~]# ll
总用量
-rw-------. root root 12月 : anaconda-ks.cfg
drwxr-xr-x. root root 12月 : cmake-3.7.-Linux-x86_64
-rw-r--r--. root root 12月 : cmake-3.7.-Linux-x86_64.tar.gz
drwxr-xr-x. root root 12月 : llvm-src
-rw-r--r--. root root 1月 : llvm-src.tar.gz
drwxr-xr-x. 8月 vim74
-rw-r--r--. root root 12月 : vim-7.4.tar.bz2
-rw-r--r--. root root 1月 : 正则练习regexp.txt

不过以上设置只对当前shell连接生效,新开的shell还是用的原来的设置。

永久生效

1) XShell属性设置

XShell连接CentOS 7.2显示中文乱码问题的解决方法

2) Linux环境变量设置

[root@min-base ~]# vim /etc/profile

在末尾追加

export LANG=zh_CN.gbk

就可以了。

然而。。。。。。我发现对插在Linux机器上的U盘仍然不能正确识别出中文目录、中文文件

原来另有蹊跷,就是在挂载U盘的时候设置下字符集

[root@min-base ~]# mount -o iocharset=gbk /dev/sdb4 /mnt

这样设置一般差不多就可以解决了。

不过此操作引发了导入xxx.sql文件时数据库中文乱码问题,有待研究...

上一篇:docker on centos


下一篇:linux上备份Oracle时EXP-00091的错误解决方法