Home>Article>Operation and Maintenance> How to modify the character set in Linux
Modification method: 1. Open the "/etc/sysconfig/i18n" file; 2. Modify the values of the "LANG", "SUPPORTED", and "SYSFONT" items; 3. Save and exit the file; 4. Execute "#source /etc/sysconfig/i18n" command is enough.
#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.
1. Check the character set
The character set is reflected in the system as an environment variable, which checks the way the current terminal uses the character set. There are several ways:
Method 1
# echo $LANG en_US.UTF-8
Method 2
# env |grep LANG LANG=en_US.UTF-8
Method 3
# export |grep LANG declare -x LANG="en_US.UTF-8"
Method 4
# locale -a //查看本地字符集 # locale -m //查看所有支持的字符集
The difference between the three commands set, env and export
set Displays the variables of the current shell, including the variables of the current user
env Display the variables of the current user
export Display the shell variables currently exported to user variables
set Used to display local variables
env Used to display the environment Variable
export is used to display and set environment variables
For example, set the user LANG
View LANG env | grep LANG
Settings LANG export LANG=zh_CH.GBK
2. How to modify the character set
It should be noted that if the default language is en_US.UTF -8. Chinese cannot be displayed and input under Linux character and graphical interfaces. If the default language is Chinese, such as zh_CN.GB18030 or
zh_CN.gb2312, the character interface cannot be displayed and input, but the graphical interface can.
There are two ways to modify it:
1. To modify the variable directly, use the following two commands:
# LANG=xxx 或者 export LANG=xxx; # LC_ALL=”xxx” 或者 export LC_ALL="xxx";
Note: xxx is the character set to be modified.
To view the standard character set, use the locale –a command. Commonly used ones are zh_CN.GB2312, zh_CN.GB18030 or zh_CN.UTF-8, en_US.UTF-8, etc. ,But the above modification will only take effect in the current shell, and this environment variable will disappear when you create a new shell.
Therefore, when you log in to the system and execute the "LANG=" command, there will be no garbled characters, which means that the display of the character set is cancelled.
To cancel the character set, you can also execute the command [root@ ~]# unset LANG.
2. Modify the file method and control it by configuring the /etc/sysconfig/i18n file
# vim /etc/sysconfig/i18n LANG="en_US.UTF-8" //当前系统的语言环境变量 SUPPORTED="zh_CN.UTF-8:zh_CN.GB18030" //系统预置了那些语言支持 ,不在项目中的语言不能正常 显示 SYSFONT="latarcyrheb-sun16" //定义控制台终端字体,你文本登录的时候显示的字体就 是这个 latarcyrheb-sun16
To make the modified file effective after saving and exiting, execute the following command: Restart to take effect
#source /etc/sysconfig/i18n
Related recommendations: "Linux Video Tutorial"
The above is the detailed content of How to modify the character set in Linux. For more information, please follow other related articles on the PHP Chinese website!