# 查看当前系统编码设置
locale
# 设置UTF-8编码(临时生效)
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
# 永久设置(编辑/etc/locale.conf或~/.bashrc)
echo 'LANG=en_US.UTF-8' | sudo tee -a /etc/locale.conf
echo 'LC_ALL=en_US.UTF-8' | sudo tee -a /etc/locale.conf
# 转换文件编码为UTF-8
iconv -f GBK -t UTF-8 input.txt > output.txt
# 查看文件编码
file filename.txt
# 连接时指定编码
ssh -o "SendEnv LANG en_US.UTF-8" user@host
# 或在服务端配置(编辑/etc/ssh/sshd_config)
AcceptEnv LANG LC_*
# Debian/Ubuntu
sudo apt install locales
sudo dpkg-reconfigure locales
# RHEL/CentOS
sudo yum install glibc-common
sudo localedef -v -c -i en_US -f UTF-8 en_US.UTF-8
# 确保安装了完整字体
sudo apt install fonts-noto-cjk # 中日韩字体
sudo apt install fonts-powerline # 常用符号字体
通过以上方法,大多数Linux终端乱码问题都能得到有效解决。如问题依旧,可能需要检查特定应用程序的编码设置或日志文件以获取更多信息。