strings
命令用于从二进制文件中提取可打印的字符串。如果你想在一个特定类型的文件中查找字符串,你可以结合使用 find
命令和 strings
命令。
以下是一个示例,展示了如何在当前目录及其子目录中的所有 .txt
文件中查找包含特定字符串(例如 “example”)的文件:
find . -type f -name "*.txt" -exec strings {} \; | grep "example"
这个命令的解释如下:
find .
:从当前目录开始搜索。-type f
:只搜索文件。-name "*.txt"
:只搜索扩展名为 .txt
的文件。-exec strings {} \;
:对找到的每个文件执行 strings
命令。| grep "example"
:将 strings
命令的输出传递给 grep
命令,以筛选出包含 “example” 字符串的行。这样,你就可以看到在所有 .txt
文件中包含 “example” 字符串的那些文件的相应字符串。