2013/12/05

[Linux] 常用指令:grep

除了find之外,還有一個類似的指令是grep,這指令主要用來搜尋檔案裡相關的程式碼結果,在trace code的時候都非常的好用。

用法:
grep [-acinv] [--color=auto] 'find things' filename

-d, --directories=ACTION  how to handle directories;
-R, -r, --recursive       equivalent to --directories=recurse
-n, --line-number         print line number with output lines


假設我們要在資料夾所有檔案中(不限檔名,使用"*")找尋有關鍵字socket()的函數,並且把檔案所在(-r)及行數(-n)印出來,使用以下指令

grep -rn socket\(\) *

就可以得到搜尋的行數及檔案結果。

沒有留言:

張貼留言