在 Linux 下,strings 常用于从二进制文件中提取可打印字符串。如果你要批量处理多个文件,通常结合 find、xargs 或 shell 循环即可。
下面按常见场景给你几种做法。
find + -execfind /path/to/dir -type f -exec strings {} \;
如果你只想处理某类文件(如 .bin):
find /path/to/dir -type f -name "*.bin" -exec strings {} \;
find + xargs(更高效)find /path/to/dir -type f -print0 | xargs -0 strings
处理特定后缀:
find /path/to/dir -type f -name "*.so" -print0 | xargs -0 strings
for f in /path/to/dir/*; do
[ -f "$f" ] && strings "$f" > "$f.txt"
done
例如:
a.bin → a.bin.txt
b.bin → b.bin.txt
find /path/to/dir -type f -exec strings {} \; > all_strings.txt
或:
cat /path/to/dir/* | strings > all_strings.txt
(仅适用于普通文件,不推荐用于二进制混合)
find /path/to/dir -type f | while read f; do
echo "===== $f ====="
strings "$f"
done > result.txt
strings -n 6 file # 最少 6 个字符
strings -e l file # 16-bit little endian
strings -e B file # 32-bit big endian
批量示例:
find . -type f -print0 | xargs -0 strings -n 6
-print0 | xargs -0 避免文件名空格问题-n 减少噪音file 先过滤二进制文件:find . -type f -exec sh -c 'file "$1" | grep -q ELF && strings "$1"' _ {} \;
如果你能说清楚:
我可以给你更精确的脚本。