在 Linux 下,strings 命令用于从二进制文件或数据中抽取可打印字符串。如果你想要批量处理多个文件,常见做法有几种,下面按使用场景说明。
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"' _ {} \;
mkdir strings_out
for f in *; do
[ -f "$f" ] && strings "$f" > "strings_out/$f.txt"
done
strings -n 8 file
批量:
find . -type f -exec strings -n 8 {} \;
例如找包含 password 的字符串:
find . -type f -exec strings {} \; | grep -i password
或更高效:
find . -type f -print0 | xargs -0 strings | grep -i password
find . -type f -print0 | xargs -0 -P 4 strings
-P 4:4 个并行进程for bin in /usr/bin/*; do
echo "=== $bin ==="
strings -n 6 "$bin" | grep -i error
done
| 需求 | 推荐命令 |
|---|---|
| 当前目录 | for f in *; do strings "$f"; done |
| 递归目录 | find . -type f -exec strings {} \; |
| 输出到文件 | strings file > out.txt |
| 并行处理 | xargs -P |
| 过滤内容 | `strings |
如果你能说明:
我可以给你更精确的命令。