在 Linux 下“批量运行 strings”通常指对多个文件(或目录下所有文件)依次执行 strings 并收集结果。下面按常见场景给你几种做法。
for 循环for f in *; do
echo "==== $f ===="
strings "$f"
done
只处理普通文件:
for f in *; do
[ -f "$f" ] && strings "$f"
done
findfind . -type f -exec strings {} \;
每个文件加文件名:
find . -type f -exec sh -c 'echo "== $1 =="; strings "$1"' _ {} \;
> strings.txt
for f in *; do
[ -f "$f" ] && {
echo "==== $f ====" >> strings.txt
strings "$f" >> strings.txt
}
done
xargs -Pfind . -type f | xargs -P 8 -I {} sh -c 'echo "== {} =="; strings "{}"'
-P 8 表示 8 个进程并行(按 CPU 核数调整)
strings file | grep -i "password"
批量:
find . -type f -exec strings {} \; | grep -i "error"
strings -n 8 file
批量:
find . -type f -exec strings -n 8 {} \;
find ./bin -type f -exec sh -c 'echo "== $1 =="; strings -n 6 "$1"' _ {} \; > out.txt
如果你能说明:
我可以给你更精确的命令。