Ubuntu18设置中文支持

Table of Contents

安装相关依赖包

sudo apt install language-pack-zh-han*

cd
sed -i -E -e '/# Chinese char support start/,/# Chinese char support stop/d' .bashrc
cat >> .bashrc <<EOF
# Chinese char support start
export LANG="en_US.UTF-8"
export LC_CTYPE="zh_CN.UTF-8"
# Chinese char support stop

EOF

sudo su

cd

sed -i -E -e '/# Chinese char support start/,/# Chinese char support stop/d' .bashrc
cat >> .bashrc <<EOF
# Chinese char support start
export LANG="en_US.UTF-8"
export LC_CTYPE="zh_CN.UTF-8"
# Chinese char support stop

EOF

sed -i -E -e '/# Chinese char support start/,/# Chinese char support stop/d' /etc/profile
cat >> /etc/profile <<EOF
# Chinese char support start
export LANG="en_US.UTF-8"
export LC_CTYPE="zh_CN.UTF-8"
# Chinese char support stop

EOF

[ ! -e /var/lib/locales/supported.d/local ] && touch /var/lib/locales/supported.d/local
[ -e /var/lib/locales/supported.d/local ] && sed -i -E -e '/# Chinese char support start/,/# Chinese char support stop/d' /var/lib/locales/supported.d/local

cat >> /var/lib/locales/supported.d/local <<EOF
# Chinese char support start
zh_CN.UTF-8 UTF-8
zh_CN.GB18030 GB18030
zh_CN.GBK GBK
# Chinese char support stop
EOF

sed -i -E -e '/" Chinese char support start/,/" Chinese char support stop/d' /etc/vim/vimrc

cat >> /etc/vim/vimrc <<EOF
" Chinese char support start
set fileencodings=utf-8,gbk,utf-16le,cp1252,iso-8859-15,ucs-bom
set termencoding=utf-8
set encoding=utf-8
" Chinese char support stop
EOF

cat <<EOF | sudo tee /etc/default/locale
LANG="en_US.UTF-8"
LANGUAGE="en_US:en"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_IDENTIFICATION="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"
EOF

locale-gen

exit

exec bash
cd
echo "中文支持测试" > t.txt
cat t.txt
rm -f t.txt

重启系统,查看find ls vim nano less cat几个命令是否正常显示中文

sudo init 6

参考文档

https://blog.csdn.net/wbj217/article/details/85263723

https://blog.csdn.net/qq_19004627/article/details/101780256