How to resolve Chinese garbled characters in CentOS command line display?
The reason why Chinese characters are displayed as garbled in CentOS command line might be due to incorrect system character set settings. Here is a solution:
- Check the system character set settings: Use the following command to view the current character set setting:
- What is the value of the $LANG variable?
- If the output appears as gibberish or is not in the Chinese character set (such as en_US.UTF-8), adjustments need to be made.
- Change the character set settings: Execute the following command to change the character set to Chinese character set (such as zh_CN.UTF-8):
- Open the file /etc/locale.conf using the vi text editor.
- Add the following content to the document:
- Set the language to Chinese (Simplified) and the locale to Chinese (Simplified).
- Save and exit the file.
- Update character set settings: Execute the following command to make the modified character set settings take effect:
- Open the file located in /etc/locale.conf.
- Alternatively, you can log back in to the system.
- Restart the terminal: close the current terminal window and reopen it. It should display Chinese characters correctly.
If the above methods do not solve the problem, it may be due to missing or corrupted font files. You can try installing or reinstalling Chinese font files, such as:
yum install -y wqy-zenhei-fonts
After the installation is complete, simply restart the terminal.