温馨提示×

Strings命令报错怎么办

小樊
47
2026-08-02 07:40:00
栏目: 编程语言

strings 命令报错时,原因通常和 命令不存在、参数写错、文件问题或环境不兼容 有关。下面按常见情况给你排查思路。


一、常见报错与解决办法

1️⃣ command not found

bash: strings: command not found

原因

  • 系统没安装 binutils
  • 或不在 PATH

解决

  • Ubuntu / Debian

    sudo apt update
    sudo apt install binutils
    
  • CentOS / RHEL / Rocky

    sudo yum install binutils
    
  • Arch

    sudo pacman -S binutils
    
  • macOS

    brew install binutils
    

    macOS 自带 strings,但路径可能不同

  • 检查是否存在:

    which strings
    

2️⃣ strings: invalid option -- 'x'

strings: invalid option -- 'x'

原因

  • 参数写错
  • 不同系统参数不兼容

解决

  • 查看帮助:
    strings --help
    
  • 常见正确用法:
    strings file
    strings -n 6 file
    strings -a file
    

3️⃣ strings: file: No such file or directory

strings: test.bin: No such file or directory

原因

  • 文件路径错误
  • 文件名含空格或特殊字符

解决

  • 确认文件存在:
    ls -l file
    
  • 使用绝对路径或引号:
    strings "./my file.bin"
    

4️⃣ strings: file: File format not recognized

strings: file: File format not recognized

原因

  • 不是二进制 / ELF 文件
  • 文件损坏

解决

  • 强制读取所有数据:
    strings -a file
    
  • 检查文件类型:
    file file
    

5️⃣ Permission denied

strings: Permission denied

解决

chmod +r file
# 或
sudo strings file

6️⃣ macOS 上行为异常

macOS 的 strings 和 Linux 不完全一样。

建议

/usr/bin/strings file

或安装 GNU 版本:

brew install binutils

二、推荐的安全用法 ✅

strings -a -n 6 filename

说明:

  • -a:扫描整个文件
  • -n 6:只显示长度 ≥ 6 的字符串

三、如果还不行

你可以把 完整报错信息 + 系统版本 + 命令 发给我,例如:

系统:Ubuntu 22.04
命令:strings test.bin
报错:strings: invalid option -- 't'

我可以直接帮你定位 ✅

0