在 Ubuntu 中出现文件乱码,通常是因为编码不一致或系统语言环境设置问题。下面按常见场景给你解决方案:
locale
如果看到 LANG=C 或 UTF-8 缺失,说明有问题。
sudo apt update
sudo apt install language-pack-zh-hans
sudo dpkg-reconfigure locales
zh_CN.UTF-8zh_CN.UTF-8或修改 ~/.bashrc:
export LANG=zh_CN.UTF-8
export LC_ALL=zh_CN.UTF-8
然后:
source ~/.bashrc
file 文件名
iconv -f GBK -t UTF-8 原文件 -o 新文件
vim 文件名
:set fileencoding=utf-8
:wq
Windows 常用 GBK,Ubuntu 默认 UTF-8。
unzip -O GBK 文件.zip
(新版 unzip 支持 -O)
LANG=C unzip 文件.zip
gsettings set org.gnome.gedit.preferences.encodings auto-detected "['UTF-8','GBK','GB18030','BIG5']"
编辑 /etc/samba/smb.conf:
[global]
unix charset = UTF-8
dos charset = CP936
然后重启:
sudo systemctl restart smbd
✅ 系统不是 UTF-8
✅ Windows 文件用 GBK
✅ 终端字体不支持中文
✅ 压缩包在非 UTF-8 下创建
如果你愿意,可以告诉我:
file 文件名 的输出我可以更精准地帮你解决。