最近想解决Linux(CentOS8)在TTY下显示中文的问题,最后发现是徒劳,TTY本来就不能显示中文等Unicode字符。
在CentOS8中安装中文包:sudo dnf install langpack-zh_CN
CentOS8开始使用dnf工具。
临时修改Terminal的语言为中文:
$ LANG="zh_CN.UTF-8"
这个修改是临时的,logout后或者是别的Terminal,都无效。
在TTY下,无法显示中文:
TTY不能显示中文
中文部分全部都显示为小方块。
用别的Terminal登录,就可以正常显示中文:
[xinlin@localhost gps]$ weasdfasdfa
-bash: weasdfasdfa: command not found
[xinlin@localhost gps]$ echo $LANG
en_US.UTF-8
[xinlin@localhost gps]$ LANG="zh_CN.UTF-8"
[xinlin@localhost gps]$ echo $LANG
zh_CN.UTF-8
[xinlin@localhost gps]$ awerqwerwer
-bash: awerqwerwer: 未找到命令
网络上有人解释过这个问题:
明确的和你说,TTY 不支持中文!
Linux kernel maintainers do not accept patches for better Unicode support on the console because the console is to be used as an emergency interface. What needs to be done is write a terminal emulator for the Linux framebuffer that undertakes the support for Unicode. Something like a 'getty' replacement. This aspect of open-source development did not receive yet much attention
大意是:linux核心机制不接受任何的unicode补丁在Console层面,因为Console是作为一种紧急接口被使用...... 而且目前开源开发组也没有过多的关注这一点.
从这里可以得出一个结论,目前tty是给管理员紧急修复系统时所使用的界面,故而从内核层面就不支持加载unicode包;但是模拟接口比如用SSH之类的登陆,是可以支持中文的!
看来一般工作时,Linux还是要配合一个Terminal才行!