首先查看一下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