在 Linux 下,批量用 strings 提取文件中可打印字符串,常见有几种做法,取决于你的使用场景(目录、递归、输出方式等)。
for f in *; do
echo "==== $f ===="
strings "$f"
done
如果你只想处理普通文件:
for f in *; do
[ -f "$f" ] && strings "$f"
done
find + xargs(高效)find . -type f -print0 | xargs -0 strings
find + while(更可控)find . -type f | while read -r f; do
echo "==== $f ===="
strings "$f"
done
只处理 ELF 文件:
find . -type f -exec file {} \; | grep ELF | cut -d: -f1 | xargs strings
mkdir strings_out
for f in *; do
[ -f "$f" ] && strings "$f" > "strings_out/$f.txt"
done
递归版本:
find . -type f | while read -r f; do
out="strings_out/${f//\//_}.txt"
strings "$f" > "$out"
done
strings 参数strings -n 6 file # 最少 6 个字符
strings -e l file # 16-bit little endian
strings -t x file # 显示偏移(十六进制)
find . -type f -print0 | xargs -0 strings | grep -i password
如果你能说明:
我可以给你更精确的命令。