温馨提示×

debian strings编码怎么设

小樊
43
2026-10-07 01:02:54
栏目: 智能运维

在 Debian(及一般 Linux)里,**“strings 编码”**通常指两件事之一,下面分别说明:


一、strings 命令本身的编码/字符集设置

strings 默认只提取可打印字符,是否支持中文、UTF‑8 等,取决于你使用的 strings 实现。

1. GNU binutils 的 strings(最常见)

strings file

指定字符编码(重要)

strings -e S file   # 7-bit ASCII(默认)
strings -e B file   # 16-bit Big Endian
strings -e L file   # 16-bit Little Endian
strings -e U file   # UTF-8(推荐用于中文)

✅ 查看 UTF‑8 字符串(包括中文):

strings -e U file

二、终端 / 系统编码设置(影响显示)

即使 strings 提取了 UTF‑8 内容,如果终端编码不对,也会乱码。

1. 查看当前编码

locale

正常应为:

LANG=en_US.UTF-8
LC_ALL=en_US.UTF-8

2. 设置 UTF‑8(Debian)

sudo dpkg-reconfigure locales

勾选:

en_US.UTF-8
zh_CN.UTF-8

然后:

export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

三、中文乱码常见解决方法

strings -e U binary | iconv -f UTF-8 -t UTF-8

或:

file binary

确认文件真实编码,再用 iconv 转换。


四、如果 strings 不支持 UTF‑8(老版本)

可用替代方案:

grep -a -o '[\x20-\x7E]\{4,\}' file

或:

strings file | iconv -f GBK -t UTF-8

总结

需求 命令
提取 UTF‑8 字符串 strings -e U file
设置系统编码 LANG=en_US.UTF-8
中文乱码 iconv -f GBK -t UTF-8

如果你能说明:是看二进制里的字符串,还是终端显示乱码,我可以给更精确的命令。

0 踩