How to solve Chinese garbled characters on Mac console

1. Mac garbled code phenomenon

When viewing the directory on Mac Console, the Chinese character ???garbled characters are displayed, as shown in the following figure:

Use the locale command to check the locale and find that the encoding is en_CN.UTF-8, which is obviously a problem.

panda@pan ~ % locale
LANG="en_CN.UTF-8"
LC_COLLATE="C"
LC_CTYPE="C"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=

2. Mac encoding configuration modification

Check the shell type used by the terminal. The default is zsh.

panda@pan ~ % echo $SHELL
/bin/zsh

Modify the ~/.zshrc user configuration file and set it to Chinese encoding.

panda@pan ~ % open ~/.zshrc
export LANG=zh_CN.UTF-8

Make the configuration take effect immediately.

source ~/.zshrc

Execute the locale command to check the locale. It has been changed to Chinese language.

panda@pan ~ % locale
LANG="zh_CN.UTF-8"
LC_COLLATE="zh_CN.UTF-8"
LC_CTYPE="zh_CN.UTF-8"
LC_MESSAGES="zh_CN.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_NUMERIC="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_ALL=

Verify whether the modification is successful and the Chinese display is normal.​ 

Guess you like

Origin blog.csdn.net/BlogPan/article/details/132713747