Linux服务器中文乱码的问题

Linux服务器系统的CentOS 7

文件名是中文全是?的乱码,执行 locale 查看编码格式,内容如下

[root@iZ2ze3n2wuzr91sx0vgwwdZ ~]# locale
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

 

发现一个错误信息:locale: Cannot set LC_ALL to default locale: No such file or directory

为了解决这个问题,要设置 LC_ALL 的参数,

[root@iZ2ze3n2wuzr91sx0vgwwdZ ~]# export LC_ALL="en_US.UTF-8"
-bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
-bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)

  执行这个命令也发生了 warning,再次执行 locale 命令,错误信息依然存在,但 LC_ALL 已经有值了,但与其他参数不同的是没有双引号,看来依然不对。

[root@iZ2ze3n2wuzr91sx0vgwwdZ ~]# locale
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8

  

  继续执行命令:sudo localedef -i en_US -f UTF-8 en_US.UTF-8

  这个命令执行成功了,在使用 locale 验证一下,问题解决。

[root@iZ2ze3n2wuzr91sx0vgwwdZ ~]# locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8

 

posted @ 2023-02-01 02:51  闲人鹤  阅读(966)  评论(0编辑  收藏  举报