定義及功能解釋
Linux系統(tǒng)中grep命令是一種強大的文本搜索工具,它能使用正則表達式搜索文本,并把匹 配的行打印出來。grep全稱是Global Regular Expression Print,表示全局正則表達式版本,它的使用權限是所有用戶。
grep的工作方式是這樣的,它在一個或多個文件中搜索字符串模板。如果模板包括空格,則必須被引用,模板后的所有字符串被看作文件名。搜索的結果被送到標準輸出,不影響原文件內容。
grep [option] pattern file
命令練習
less /etc/passwd |grep 'systemd'
less /etc/passwd |grep -w 'system' # 精確匹配
less /etc/passwd |grep -i System #不區(qū)分大小寫
less /etc/passwd |grep -nie System -e syslog -e backup #標行號,不區(qū)分大小寫,either 關系
less /etc/passwd |grep -f tex.txt # 查找文件所包含的字符
命令演示結果:

圖片.png

命令演示,-nie -e