> grep ^[^#] rumenz.txt
> grep ^# rumenz.txt
> grep "rumenz" 1.txt
> grep "rumenz" *.html
> grep -in "rumenz" 1.txt
> grep -c "rumenz" 1.txt
> grep -l "rumenz" *
-l: 查询多文件的时候只输出包含匹配字符的文件名
> grep -rl "rumenz" .
不会输出任何信息,如果命令运行成功返回0,失败则返回非0值。一般用于条件测试。
> grep -q "rumenz" 1.txt
> grep -R --exclude-dir="tmp" "rumenz"
tmp 中的文件不用查找
> cat 1.txt | grep -v "^s*$"
> cat 1.txt | grep -v "^#"
> cat 1.txt | grep -v "^$" | grep -v "^#"
> grep -A 5 'rumenz' 1.txt
> grep -B 5 'rumenz' 1.txt
> grep -C 5 'rumenz' 1.txt
> grep "abc" 1.txt //结果为abcd, abcde, abc等
> grep -w "abc" 1.txt
> cat 1.txt | grep -e "ab" -e "ef" -o
> grep -r "rumenz" --include *.{html,php}
> grep -r "rumenz" --exclude "README" .
> cat filelist
aaa
bbb
rumenz
> grep -r "rumenz" --exclude-from filelist .
原文链接
:https://rumenz.com/rumenbiji/linux-grep-skills.html