
背景
使用U盘往Windows主机、Linux主机传文件还是经常的事,但有时候文件名有中文,传到Linux机器会有乱码,选择起来也很麻烦,最近刚好遇到,写下解决方法。
环境
Linux
[root@min-base ~]# cat /etc/RedHat-release CentOS Linux release 7.2.1511 (Core) [root@min-base ~]# echo $LANG en_US.UTF-8 [root@min-base ~]#
Windows XShell
问题
txt文件是用Xftp直接从Windows上拖过来的,在Linux机上显示乱码了。
[root@min-base ~]# ll total 801272 -rw-------. 1 root root 996 Dec 1515:56 anaconda-ks.cfg drwxr-xr-x. 6 root root 48 Dec 2107:13 cmake-3.7.1-Linux-x86_64 -rw-r--r--. 1 root root 30679418 Dec 2107:13 cmake-3.7.1-Linux-x86_64.tar.gz drwxr-xr-x. 4 root root 29 Dec 2106:09 llvm-src -rw-r--r--. 1 root root 779956643 Jan 117:40 llvm-src.tar.gz drwxr-xr-x. 8100010004096 Aug 102013 vim74 -rw-r--r--. 1 root root 9843297 Dec 2105:04 vim-7.4.tar.bz2 -rw-r--r--. 1 root root 975 Jan 1006:01 ??????ϰregexp.txt [root@min-base ~]#
解决
一般这种问题是文件的编码字符集、Shell编码字符集、XShell编码字符集不匹配,设置匹配就可以了。
临时办法
1)简体中文的Windows一般使用GB字符集,这里将XShell设置为GBK
2)
Linux主机
[root@min-base ~]# export LANG=zh_CN.gbk
再试,就可以正常显示中文了。
[root@min-base ~]# ll 总用量 801272 -rw-------. 1 root root 996 12月 1515:56 anaconda-ks.cfg drwxr-xr-x. 6 root root 48 12月 2107:13 cmake-3.7.1-Linux-x86_64 -rw-r--r--. 1 root root 30679418 12月 2107:13 cmake-3.7.1-Linux-x86_64.tar.gz drwxr-xr-x. 4 root root 29 12月 2106:09 llvm-src -rw-r--r--. 1 root root 779956643 1月 117:40 llvm-src.tar.gz drwxr-xr-x. 8100010004096 8月 102013 vim74 -rw-r--r--. 1 root root 9843297 12月 2105:04 vim-7.4.tar.bz2 -rw-r--r--. 1 root root 975 1月 1006:01 正则练习regexp.txt
不过以上设置只对当前shell连接生效,新开的shell还是用的原来的设置。
永久生效
1) XShell属性设置
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文件时数据库中文乱码问题,有待研究…
文章来源网络,作者:运维,如若转载,请注明出处:https://shuyeidc.com/wp/202529.html<