grep 'word' filename grep 'string1 string2' filename cat otherfile | grep 'something' command | grep 'something' command option1 | grep 'data' grep --color 'data' fileName
在某個文件裡搜索error字符串$ grep "error" log.txt
$ grep -i "ErroR" log.txt
$ grep -r "exception" log.txt
如果你搜索boo,查詢結果可能包含fooboo,boo123, booooom,等等,可以使用-w來限定全字匹配$ grep -w "boo" /path/to/file
$ grep -w 'word1|word2' /path/to/file
$ grep -c 'word' /path/to/file
另外加-n的話, 會在結果中,列出匹配字符串的序列號,並且會列出內容$ grep -n 'word' /path/to/file
$ grep -v bar /path/to/file
$ grep -l 'main' *.pls
$
grep --color Oracle /etc/passwd
ls -l | grep -i xyz
ls 列出當前目錄下的文件和文件夾,| 是管道傳遞給後面的一個程序,grep再是進行模式匹配
例如:ls *.pls | grep -i --color "MM"
========EOF=========