[root@www ~]# grep [-acinv] [--color=auto] '搜尋字串' filename 選項與參數: -a :將 binary 檔案以 text 檔案的方式搜尋資料 -c :計算找到 '搜尋字串' 的次數 -i :忽略大小寫的不同,所以大小寫視為相同 -n :順便輸出行號 -v :反向選擇,亦即顯示出沒有 '搜尋字串' 內容的那一行! --color=auto :可以將找到的關鍵字部分加上顏色的顯示喔!
grep "abc" file.txt
2.如果要在子資料夾間搜尋,可以用
grep -r "abc" .
來完成,以 -r 來表示要遞迴子資料夾,而 . 則是代表由所在資料夾開始搜尋。
3.還可以用 --include 來指示目標檔案名稱:
grep -r --include="*.php" abc .
或用 --exclude 來排除一些檔案:
grep -r --exclude="*.jpg" search_text .
@參考資料:
1.http://linux.vbird.org/linux_basic/0320bash.php#grep2.http://www.openfoundry.org/tw/foss-programs/8628--linux-
沒有留言 :
張貼留言