温馨提示×

如何批量处理debian strings

小樊
42
2026-09-16 06:55:50
栏目: 智能运维

在 Debian 系统里,“strings”通常指两件事之一:

  1. strings 命令:从二进制/数据文件中提取可打印字符串
  2. gettext 的 .po / .pot 国际化字符串:Debian 软件包本地化用

下面分别说明批量处理方法。


一、批量使用 strings 命令(提取二进制中的字符串)

1. 批量处理一个目录下的所有文件

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

2. 只处理 ELF 可执行文件

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

3. 每个文件单独输出,并标注文件名

for f in /usr/bin/*; do
  echo "==== $f ===="
  strings "$f"
done > strings_report.txt

4. 并行加速(适合大量文件)

apt install parallel
find . -type f | parallel strings > all.txt

二、批量处理 Debian 国际化字符串(.po / .pot)

1. 批量提取 .po 文件中的 msgid / msgstr

for po in *.po; do
  echo "== $po =="
  msgattrib --no-obsolete "$po"
done

2. 批量合并 .pot 模板到 .po

for po in *.po; do
  msgmerge --update "$po" template.pot
done

3. 批量编译 .po 为 .mo

for po in *.po; do
  msgfmt "$po" -o "${po%.po}.mo"
done

4. 批量检查未翻译条目

for po in *.po; do
  echo "$po: $(msgfmt --statistics "$po" 2>&1)"
done

三、Debian 打包场景(dh / debhelper)

如果你是在 Debian 打包:

# 自动提取字符串
dpkg-buildpackage

# 或手动
dh_make
debchange

通常不需要手动批量处理 strings,debhelper 会自动调用 xgettext / intltool。


四、常见组合示例

提取某软件所有二进制字符串并去重:

find /opt/app -type f -exec file {} \; |
grep ELF | cut -d: -f1 |
xargs strings |
sort -u > app_strings.txt

如果你能具体说明:

  • 是 二进制 strings 还是 翻译字符串
  • 是否用于 安全分析 / 本地化 / 打包

我可以给你更精准的脚本。

0 踩