Hello! 欢迎来到小浪云!


Linux strings命令怎样定制输出格式


avatar
小浪云 2025-04-23 17

strings 命令用于从二进制文件中提取可打印的字符串

  1. 使用 -n 选项指定最小字符串长度:

    strings -n <length> <file> 

    例如,要提取长度至少为 6 的字符串,可以使用:

    strings -n 6 <file> 
  2. 使用 -e 选项指定字符编码:

    strings -e <encoding> <file> 

    其中 可以是 ASCII, ibm, utf8, ucs2, utf16le, utf16be, utf32le, utf32be 等。

    例如,要使用 UTF-8 编码提取字符串,可以使用:

    strings -e utf8 <file> 
  3. 使用 -t 选项以十六进制格式显示字符串:

    strings -t <format> <file> 

    其中 可以是 x(默认值,显示为十六进制),d(显示为十进制)或 o(显示为八进制)。

    例如,要以十进制格式显示字符串,可以使用:

    strings -t d <file> 
  4. 使用 -T 选项指定输出格式:

    strings -T <type> <file> 

    其中 可以是 s(显示字符串),a(显示地址),i(显示整数)或 b(显示字节)。

    例如,要同时显示字符串及其地址,可以使用:

    strings -T sa <file> 

你可以根据需要组合这些选项来定制 strings 命令的输出格式。例如,要提取长度至少为 6 的 UTF-8 编码字符串,并以十六进制和十进制格式显示它们及其地址,可以使用:

strings -n 6 -e utf8 -T sxd <file> 

相关阅读