温馨提示×

如何保存linux strings输出

小樊
39
2026-09-20 18:52:21
栏目: 智能运维

在 Linux 中,strings 命令用于从二进制文件或数据中抽取可打印字符串。如果你想保存 strings 的输出,常见做法有以下几种:


1. 重定向到文件(最常用)

strings file.bin > output.txt
  • >:覆盖写入
  • >>:追加写入

示例:

strings /bin/ls > ls_strings.txt

2. 同时查看并保存(tee)

strings file.bin | tee output.txt
  • 屏幕上能看到输出
  • 同时保存到 output.txt

追加模式:

strings file.bin | tee -a output.txt

3. 保存带行号的输出

strings -n 6 file.bin | nl > output.txt
  • -n 6:只显示长度 ≥ 6 的字符串
  • nl:加行号

4. 保存并结合 grep 过滤结果

strings file.bin | grep -i "password" > passwords.txt

5. 保存为结构化格式(如 CSV)

strings file.bin | sed 's/"/""/g' | awk '{print "\""$0"\""}' > output.csv

6. 保存并保留编码(如 UTF-8)

LC_ALL=C strings file.bin > output.txt

或:

strings -e l file.bin > output.txt
  • -e l:16-bit little-endian

7. 保存到日志并后台运行

nohup strings bigfile.bin > output.txt 2>&1 &

如果你能说明:

  • 单个文件还是目录
  • 是否要 过滤关键字
  • 是否用于 取证 / 逆向 / 日志分析

我可以给你更精确的保存方案。

0