[英]Using Ag (“The Silver Searcher”) to find hex codes
我曾經在Linux下使用find命令在php代碼中查找十六進制代碼,如下所示:
find "/www_root/myfile" -type f -name "*.php" | xargs grep -il x29
上面的命令就像一個超級按鈕,但是隨着我的文件不斷增長,我可能需要一個更快的搜索器。
我想使用The Silver Searcher ag
命令進行測試,並且一直在尋找如何使用“ ag”命令查找十六進制代碼的方法,但是在其文檔中找不到任何內容。 所以,我在這個論壇上,尋求答案,希望有人在使用silver searcher 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
因此,是的,選擇Silver Searcher是正確的選擇。 僅此而已,祝您擁有美好的一天。
還可以看看findrepo ,您可以像這樣使用:
cd /www_root/myfile && findrepo -n 'x29' '*.php'
那應該比ag
快(讓我驚訝的是,您說您的最初find | xargs grep
命令比ag
慢)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.