使用 Ag ("The Silver Searcher") 查找十六进制代码
Using Ag ("The Silver Searcher") to find hex codes
我曾经使用 linux 的查找命令在 php 代码中查找十六进制代码,如下所示:
find "/www_root/myfile" -type f -name "*.php" | xargs grep -il x29
上面的命令很有用,但随着我的文件不断增长,我可能需要一个更快的搜索器。
我想使用 The Silver Searcher ag
命令进行测试,我一直在搜索如何使用 "ag" 命令查找十六进制代码,但在他们的文档中找不到任何内容.所以,我来到这个论坛,寻求答案,希望有人有使用银搜索器搜索十六进制代码的经验ag
。
不知怎么的,早点没发现这个,现在找到了。我没看懂的其实是"ag"命令和函数可以用但是现在可以了
我会在这里分享答案,以防有人需要。为了替换我之前质疑的 find 命令,我们可以使用这个:
ag --php -l 'x29' "/www_root/myfile"
上一条命令的输出类似于:
/www_root/myfile/menus.php
如果它找到了更多文件,那么它会列出以新行“\n”分隔的文件:
/www_root/myfile/menus.php
/www_root/myfile/contents.php
如果您想知道哪些行号,您可以删除“-l”属性,然后将其替换为“--numbers”:
ag --php --numbers 'x29' "/www_root/myfile"
输出:
30:matches string found here
89:matches string found here
好的,现在我们可以将它与"cut"命令结合起来只获取行号:
ag --php --numbers 'x29' "/www_root/myfile" | cut -f1 -d:
输出:
30
89
大部分命令与 "ack" 类似,所以想要使用 "ag" 的人可以找到 "ack" 文档,因为它们已经记录了所有内容。
最后但同样重要的是,如果您想了解统计信息,可以将 --stats 添加到上述命令中,如下所示:
ag --php -l --stats 'x29' "/www_root/myfile"
这个简单的命令将输出如下所示的结果:
31 matches
1624 files searched
18686162 bytes searched
0.094022 seconds
所以,是的,选择 The Silver Searcher 是正确的选择。就这些,祝你有美好的一天。
另请查看 findrepo,您可以像这样使用它:
cd /www_root/myfile && findrepo -n 'x29' '*.php'
那应该比 ag
快(我很惊讶你说你最初的 find | xargs grep
命令比 ag
慢)
我曾经使用 linux 的查找命令在 php 代码中查找十六进制代码,如下所示:
find "/www_root/myfile" -type f -name "*.php" | xargs grep -il x29
上面的命令很有用,但随着我的文件不断增长,我可能需要一个更快的搜索器。
我想使用 The Silver Searcher ag
命令进行测试,我一直在搜索如何使用 "ag" 命令查找十六进制代码,但在他们的文档中找不到任何内容.所以,我来到这个论坛,寻求答案,希望有人有使用银搜索器搜索十六进制代码的经验ag
。
不知怎么的,早点没发现这个,现在找到了。我没看懂的其实是"ag"命令和函数可以用但是现在可以了
我会在这里分享答案,以防有人需要。为了替换我之前质疑的 find 命令,我们可以使用这个:
ag --php -l 'x29' "/www_root/myfile"
上一条命令的输出类似于:
/www_root/myfile/menus.php
如果它找到了更多文件,那么它会列出以新行“\n”分隔的文件:
/www_root/myfile/menus.php
/www_root/myfile/contents.php
如果您想知道哪些行号,您可以删除“-l”属性,然后将其替换为“--numbers”:
ag --php --numbers 'x29' "/www_root/myfile"
输出:
30:matches string found here
89:matches string found here
好的,现在我们可以将它与"cut"命令结合起来只获取行号:
ag --php --numbers 'x29' "/www_root/myfile" | cut -f1 -d:
输出:
30
89
大部分命令与 "ack" 类似,所以想要使用 "ag" 的人可以找到 "ack" 文档,因为它们已经记录了所有内容。
最后但同样重要的是,如果您想了解统计信息,可以将 --stats 添加到上述命令中,如下所示:
ag --php -l --stats 'x29' "/www_root/myfile"
这个简单的命令将输出如下所示的结果:
31 matches
1624 files searched
18686162 bytes searched
0.094022 seconds
所以,是的,选择 The Silver Searcher 是正确的选择。就这些,祝你有美好的一天。
另请查看 findrepo,您可以像这样使用它:
cd /www_root/myfile && findrepo -n 'x29' '*.php'
那应该比 ag
快(我很惊讶你说你最初的 find | xargs grep
命令比 ag
慢)