在文件中搜索指定文本:
grep "hello" test.txt
不区分大小写:
grep -i "hello" test.txt
精确匹配:
grep -w "hello" test.txt
多条件:
grep -e "hello" -e "bye" test.txt
查找返回结果同时显示行数:
grep -n "hello" test.txt
反向查找:
grep -v "hello" test.txt
在文件夹的所有文件中查找:
grep -r "hello" testDir/
同上,但只列出文件名:
grep -lr "hello" testDir/
启用正则表达式:
grep -E "hello|bye" test.txt