简短回答:strings 本身不能“判断/显示编码”,它只是按字节提取可打印字符序列,默认按 ASCII(或扩展 ASCII)看待。
下面说清楚几点:
strings 做了什么strings 做的事情是:
它不解析编码、不转换编码、不告诉你这是什么编码。
例如:
strings file.bin
如果文件里是 UTF-8 中文,而你的终端是 UTF-8,strings 可能“看起来正常”,但那是因为:
strings 与编码的关系strings 照样把字节打出来strings -n 6 file # 最少 6 个可打印字符才输出
strings -e l file # 16-bit little endian
strings -e b file # 16-bit big endian
strings -e s file # 7-bit ASCII(默认)
这些是指字符宽度/字节序,不是“编码识别”。
strings 不行,要用别的工具:
file file.bin
# 示例:UTF-8 Unicode text
enca file.bin
# 猜测编码(支持多语言)
iconv -l
# 查看支持的编码
chardet file.txt
# Python 工具,检测编码
可以配合:
strings file | iconv -f UTF-8 -t UTF-8 -c
或提取后进一步处理。
strings不能看编码,只能“把看起来像字符串的字节打印出来”;
编码识别要用file/enca/chardet等工具。
如果你有具体文件或场景(比如 ELF、日志、二进制协议),我可以给你更合适的命令。