温馨提示×

怎样批量用ubuntu strings

小樊
32
2026-09-06 13:52:53
栏目: 智能运维

在 Ubuntu 下,strings 命令常用于从二进制文件中提取可打印字符串。如果你想批量对多个文件使用 strings,常见做法如下:


一、对某个目录下的所有文件批量执行

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

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

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

for f in *; do
    if file "$f" | grep -q "ELF"; then
        echo "=== $f ==="
        strings "$f"
    fi
done

二、递归处理子目录(find 方式)

1️⃣ 递归所有文件

find . -type f -exec strings {} \;

2️⃣ 递归并标注文件名

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

3️⃣ 只处理 ELF 文件

find . -type f -exec sh -c 'file "$1" | grep -q ELF && { echo "=== $1 ==="; strings "$1"; }' _ {} \;

三、批量输出到文件

每个文件一个结果

mkdir strings_out
for f in *; do
    strings "$f" > "strings_out/$f.txt"
done

合并到一个文件

find . -type f -exec strings {} \; > all_strings.txt

四、使用 xargs(大文件更高效)

find . -type f -print0 | xargs -0 strings

五、常用 strings 参数

strings -n 6 file        # 至少 6 个字符
strings -e l file        # 16-bit little endian
strings -a file          # 扫描整个文件

如果你能说明:

  • ELF / exe / 固件 / 随意文件
  • 是否要 递归 / 输出格式 / 过滤关键字

我可以给你更精确的批量脚本。

0