$ grep ‘test' d*
$ grep ‘test' aa bb cc
$ grep ‘[a-z]\{5\}' aa
$ grep ‘w\(es\)t.*\1′ aa
$ grep magic /usr/src/Linux/Doc/* sysrq.txt:* How do I enable the magic SysRQ key? sysrq.txt:* How do I use the magic SysRQ key?
grep: sound: Is a directory
$ grep magic /usr/src/Linux/Documentation/* | less
# ps -ef | grep in.telnetd
root 19955 181 0 13:43:53 ? 0:00 in.telnetd
# more size.txt size文件的内容
b124230
b034325
a081016
m7187998
m7282064
a022021
a061048
m9324822
b103303
a013386
b044525
m8987131
B081016
M45678
B103303
BADc2345
# more size.txt | grep '[a-b]' 范围 ;如[A-Z]即A,B,C一直到Z都符合要求
b124230
b034325
a081016
a022021
a061048
b103303
a013386
b044525
# more size.txt | grep '[a-b]'*
b124230
b034325
a081016
m7187998
m7282064
a022021
a061048
m9324822
b103303
a013386
b044525
m8987131
B081016
M45678
B103303
BADc2345
# more size.txt | grep 'b' 单个字符;如[A] 即A符合要求
b124230
b034325
b103303
b044525
# more size.txt | grep '[bB]'
b124230
b034325
b103303
b044525
B081016
B103303
BADc2345
# grep 'root' /etc/group
root::0:root
bin::2:root,bin,daemon
sys::3:root,bin,sys,adm
adm::4:root,adm,daemon
uucp::5:root,uucp
mail::6:root
tty::7:root,tty,adm
lp::8:root,lp,adm
nuucp::9:root,nuucp
daemon::12:root,daemon
# grep '^root' /etc/group 匹配正则表达式的开始行
root::0:root
# grep 'uucp' /etc/group
uucp::5:root,uucp
nuucp::9:root,nuucp
# grep '\<uucp' /etc/group
uucp::5:root,uucp
# grep 'root$' /etc/group 匹配正则表达式的结束行
root::0:root
mail::6:root
# more size.txt | grep -i 'b1..*3' -i :忽略大小写
b124230
b103303
B103303
# more size.txt | grep -iv 'b1..*3' -v :查找不包含匹配项的行
b034325
a081016
m7187998
m7282064
a022021
a061048
m9324822
a013386
b044525
m8987131
B081016
M45678
BADc2345
# more size.txt | grep -in 'b1..*3'
1:b124230
9:b103303
15:B103303
# grep '$' /etc/init.d/nfs.server | wc -l
128
# grep '\$' /etc/init.d/nfs.server | wc –l 忽略正则表达式中特殊字符的原有含义
15
# grep '\$' /etc/init.d/nfs.server
case "$1" in
>/tmp/sharetab.$$
[ "x$fstype" != xnfs ] &&
echo "$path\t$res\t$fstype\t$opts\t$desc"
>>/tmp/sharetab.$$
/usr/bin/touch -r /etc/dfs/sharetab /tmp/sharetab.$$
/usr/bin/mv -f /tmp/sharetab.$$ /etc/dfs/sharetab
if [ -f /etc/dfs/dfstab ] && /usr/bin/egrep -v '^[ ]*(#|$)'
if [ $startnfsd -eq 0 -a -f /etc/rmmount.conf ] &&
if [ $startnfsd -ne 0 ]; then
elif [ ! -n "$_INIT_RUN_LEVEL" ]; then
while [ $wtime -gt 0 ]; do
wtime=`expr $wtime - 1`
if [ $wtime -eq 0 ]; then
echo "Usage: $0 { start | stop }"
# more size.txt
the test file
their are files
The end
# grep 'the' size.txt
the test file
their are files
# grep '\<the' size.txt
the test file
their are files
# grep 'the\>' size.txt
the test file
# grep '\<the\>' size.txt
the test file
# grep '\<[Tt]he\>' size.txt
the test file
g/re/p -- global - regular expression - print.
grep "sort" *.doc #见文件名的匹配
grep -c "48" data.doc #输出文档中含有48字符的行数
grep -n "48" data.doc #显示所有匹配48的行和行号
grep -vn "48" data.doc #输出所有不包含48的行
grep -i "ab" data.doc #输出所有含有ab或Ab的字符串的行
grep '[239].' data.doc #输出所有含有以2,3或9开头的,并且是两个数字的行
grep '^[^48]' data.doc #不匹配行首是48的行
grep -E '219|216' data.doc
grep '5[[:upper:]][[:upper:]]' data.doc #查询以5开头以两个大写字母结尾的行
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有