首先查看一下grep(Globally search a Regular Expression and Print)的man手冊。會看到這個是用來和正則表達式結合起來搜索文本的。
man grep
grep searches the named input FILEs (or standard input if no files are named, or if a single hyphen-minus (-) is given as file name) for lines containing a match to the given PATTERN. By default, grep prints thematching
lines.
In addition, three variant programs egrep, fgrep and rgrep areavailable. egrep is the same as grep -E. fgrep is the same asgrep -F. rgrep is the same as grep -r. Direct invocation as either egrep or fgrep is deprecated, but is provided to allow historical applications that rely on them to run unmodified.
下面就是通過一個樣例來測試一下,通過管道將ifconfig的輸出當作grep的輸入通過選項 i 來確認搜索的packets不區分大小寫。
Examples: ifconfig | grep -i packets