温馨提示×

ubuntu strings怎样批量处理

小樊
41
2026-09-24 17:43:26
栏目: 智能运维

在 Ubuntu 下,strings 命令通常用于从二进制文件中提取可打印字符串。如果你想要批量处理多个文件,常见方式有以下几种:


一、批量处理当前目录下的所有文件

1️⃣ 处理当前目录所有文件

for f in *; do
    echo "=== $f ==="
    strings "$f"
done

2️⃣ 将结果分别保存到文件

for f in *; do
    strings "$f" > "${f}.strings.txt"
done

二、批量处理指定类型文件(如 .bin)

for f in *.bin; do
    strings "$f" > "$f.txt"
done

三、递归处理子目录(find)

1️⃣ 递归查找并处理

find . -type f -exec sh -c 'strings "$1" > "$1.strings"' _ {} \;

2️⃣ 只处理二进制文件(推荐)

find . -type f -exec file {} \; | grep -i "ELF\|executable" | cut -d: -f1 | \
while read f; do
    strings "$f" > "$f.strings"
done

四、将多个文件的 strings 合并到一个文件

cat * | strings > all_strings.txt

或更安全:

for f in *; do strings "$f"; done > all_strings.txt

五、结合 grep 批量过滤关键字

for f in *; do
    strings "$f" | grep -i "password\|token" >> result.txt
done

六、使用 xargs 提高性能(文件多时)

find . -type f | xargs -I{} sh -c 'strings "{}" > "{}.strings"'

七、常见实用参数

strings -n 6 file        # 最少 6 字符
strings -e l file        # 16-bit little endian
strings -e b file        # 16-bit big endian

如果你有具体场景(比如:逆向分析 / 日志提取 / 固件解包 / CTF),我可以给你更针对性的批量脚本。

0