在 Linux 下使用 strings 命令时出现“乱码”,通常不是 strings 本身坏了,而是数据来源、编码或参数使用不匹配。下面按“原因 → 排查方法 → 解决办法”的系统思路说明。
strings 默认只提取可打印字符序列(默认长度 ≥ 4),常见“乱码”现象包括:
\xe4\xb8\xad 或方块@#%&* 或无意义字符原因
strings 用于二进制文件(ELF、so、core、磁盘镜像)排查
file yourfile
ELF、data、executable → 正常UTF-8 text → 直接用 cat / less原因
strings 原样输出字节,终端解释错误 → 乱码排查编码
file -i yourfile
# 或
enca yourfile
解决办法
strings yourfile | iconv -f gbk -t utf-8
或先转码:
iconv -f gbk -t utf-8 yourfile | strings
原因
-n 4现象
解决
strings -n 3 yourfile
strings -n 1 yourfile
原因
strings 默认只认可打印 ASCII解决(提取更多内容)
strings -e S yourfile # 16-bit
strings -e L yourfile # 32-bit little endian
strings -e B yourfile # 32-bit big endian
现象
排查
file yourfile
binwalk yourfile
排查
locale
echo $LANG
推荐
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
file yourfile
file -i yourfile
strings -n 3 yourfile | head
strings -n 3 yourfile | iconv -f gbk -t utf-8
✅ 正常二进制:
strings /bin/ls
❌ GBK 乱码:
strings gbk_file | iconv -f gbk -t utf-8
你可以直接贴:
file yourfile 输出strings 输出截图或文本我可以精准判断是编码、参数还是文件类型问题。