在 Ubuntu 下,strings 常用于从二进制文件中提取可打印字符串。如果你想批量处理多个文件,可以结合 Shell 命令来实现。
下面按常见场景给你几种做法。
for f in *; do
echo "==== $f ===="
strings "$f"
done
for f in *; do
if file "$f" | grep -q "ELF"; then
echo "==== $f ===="
strings "$f"
fi
done
find . -type f -exec strings {} \;
find . -type f -exec sh -c 'echo "==== $1 ===="; strings "$1"' _ {} \;
find . -type f -exec sh -c '
if file "$1" | grep -q "ELF"; then
echo "==== $1 ===="
strings "$1"
fi
' _ {} \;
find . -type f -name "*.so" -o -name "*bin" | while read f; do
strings "$f" > "$f.strings.txt"
done
或统一输出:
find . -type f -exec strings {} \; > all_strings.txt
strings -n 6 file # 只显示长度 ≥6 的字符串
strings -e l file # 16-bit little endian
strings -e b file # 16-bit big endian
strings -t x file # 显示字符串偏移(十六进制)
批量示例:
find . -type f -exec strings -n 6 -t x {} \;
find . -type f -print0 | xargs -0 -P 4 strings
-P 4:4 个并行进程如果你能告诉我:
我可以给你更精确的批量脚本。