可以使用 'dd' 和 'grep' 命令来实现从指定字节开始搜索指定内容。

假设要在文件 'example.txt' 中从第 100 个字节开始搜索字符串 'hello',可以使用以下命令:

dd if=example.txt skip=99 bs=1 | grep hello

解释:

  • 'dd if=example.txt':表示从文件 'example.txt' 中读取内容。
  • 'skip=99':表示跳过前 99 个字节。
  • 'bs=1':表示每次读取 1 个字节。
  • '|':表示将 'dd' 命令的输出作为 'grep' 命令的输入。
  • 'grep hello':表示在输入中搜索字符串 'hello'。

执行以上命令后,如果文件中存在以 'hello' 开头的字符串,则会显示出来。

Shell 命令:从指定字节开始搜索内容