linux 字符中文乱码 locale的设定中LANG LC_ALL LANGUAGE 发表于 2022-10-20 | 分类于 Linux | 暂无评论 locale的设定: ### LC_ALL和LANG优先级的关系:LC_ALL > LC_* > LANG locale把按照所涉及到的文化传统的各个方面分成12个大类,这12个大类分别是: 1、字符输入(LC_CTYPE) 2、数字(LC_NUMERIC) 3、比较和排序习惯(LC_COLLATE) 4、时间显示格式(LC_TIME) 5、货币单位(LC_MONETARY) 6、信息:主要是提示信息,错误信息,状态信息,标题,标签,按钮和菜单等(LC_MESSAGES) 7、姓名书写方式(LC_NAME) 8、地址书写方式(LC_ADDRESS) 9、电话号码书写方式(LC_TELEPHONE) 10、度量衡表达方式 (LC_MEASUREMENT) 11、默认纸张尺寸大小(LC_PAPER) 12、对locale自身包含信息的概述(LC_IDENTIFICATION) 使用locale查看当前系统设置: ```shell [root@iZ23hh6yk41Z ~]# locale locale: Cannot set LC_CTYPE to default locale: No such file or directory locale: Cannot set LC_ALL to default locale: No such file or directory LANG=en_US.UTF-8 LC_CTYPE=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_CTYPE to default locale: No such file or directory locale:无法将LC_CTYPE设置为默认locale:没有这样的文件或目录 locale: Cannot set LC_ALL to default locale: No such file or directory 无法将LC_ALL设置为默认语言环境:没有这样的文件或目录 说明这两个值设置有问题 可以通过locale支持的编码: ```shell [root@iZ23hh6yk41Z application]# locale -a | grep zh zh_CN zh_CN.gb18030 zh_CN.gb2312 zh_CN.gbk zh_CN.utf8 zh_HK zh_HK.big5hkscs zh_HK.utf8 zh_SG zh_SG.gb2312 zh_SG.gbk zh_SG.utf8 zh_TW zh_TW.big5 zh_TW.euctw zh_TW.utf8 ``` 现在知道LC_ALL优先级是最高的,可以直接设置LC_ALL = utf8中文编码 1:vim 打开/etc/profile文件在最下面添加如下代码 ```shell export LC_ALL="zh_CN.UTF-8" ``` 再次查看locale ```shell [root@iZ23hh6yk41Z application]# locale LANG=en_US.UTF-8 LC_CTYPE="zh_CN.UTF-8" LC_NUMERIC="zh_CN.UTF-8" LC_TIME="zh_CN.UTF-8" LC_COLLATE="zh_CN.UTF-8" LC_MONETARY="zh_CN.UTF-8" LC_MESSAGES="zh_CN.UTF-8" LC_PAPER="zh_CN.UTF-8" LC_NAME="zh_CN.UTF-8" LC_ADDRESS="zh_CN.UTF-8" LC_TELEPHONE="zh_CN.UTF-8" LC_MEASUREMENT="zh_CN.UTF-8" LC_IDENTIFICATION="zh_CN.UTF-8" LC_ALL=zh_CN.UTF-8 ``` LC_ALL已改变,无报错情况,退出重新登录即可 转载: >https://blog.csdn.net/qq_24909089/article/details/84956328