2014-09-01 55 views

回答

2

使用-l選項只顯示文件名:

grep -il "error_reporting" *php* 

對於遞歸,你可以--include玩,表示要查找文件:

grep -iRl --include=*php* "error_reporting" * 

但是,如果你想要顯示行號,那麼您需要使用-n,因此-l不會單獨工作。這是一種解決方法:

grep -iRn --include="*php*" "error_reporting" * | cut -d: -f-2 

find . -type f -name "*php*" -exec grep -iHn "error_reporting" {} \; | cut -d: -f-2. 

切口部分刪除匹配的文本,使得輸出是這樣的:

file1:line_of_matching 
file2:line_of_matching 
... 

man grep

-l, - 文件匹配

抑制正常輸出;而是打印輸出通常已經打印的每個輸入 文件的名稱。掃描 將在第一場比賽中停止。 (-l是由POSIX指定。)

--include = GLOB

只搜索其基名稱匹配GLOB(使用下--exclude如所描述的通配符 匹配)文件。

-n,--line數

前綴以其 輸入文件中的基於1的行號輸出的每一行。 (-n由POSIX指定)

+0

謝謝,但我需要遞歸和文件路徑 – totalitarian 2014-09-01 11:15:41

+0

當然!剛剛更新@totalitarian。 '--include'選項應該可以工作。讓我知道如果它對你有用! – fedorqui 2014-09-01 11:19:14

+0

謝謝,這只是打印出一個PHP文件列表 – totalitarian 2014-09-01 11:22:52

相關問題