grep在指定檔案中搜尋包含指定格式的行,并将找到的行列印出來。執行個體如下:
grep energywise * 在目前目錄搜尋帶'energywise'行的檔案
grep -r energywise * 在目前目錄及其子目錄下搜尋'energywise'行的檔案
grep -r "a and b" * 在目前目錄及其子目錄下搜尋包含"a and b"行的檔案
grep -ir SendByte * 在目前目錄及其子目錄下搜尋包含sendbyte而不管大小寫的行的檔案
grep -R "words received!" --include=*.c *
或:grep -r "words received!" --include=*.c .
在目前目錄及其子目錄下搜尋包含words received!的檔案
find在目錄樹中查找檔案。執行個體如下:
find . -name code.c
差別,grep的格式在檔案前面,而find的路徑在所要查找檔案之前。
記憶: