标签:linux grep *
grep示例:
[root@localhost ~]# ls
aaa anaconda-ks.cfg install.log install.log.syslog kuing.txt log.out mimi
查找以a开头的任何格式的文件
[root@localhost ~]# ls | grep ‘^a.*‘
aaa
anaconda-ks.cfg
查找含a字符的任何文件,*为匹配0个或n个,此语句相当于 ls
[root@localhost ~]# ls | grep ‘a*‘
aaa
anaconda-ks.cfg
install.log
install.log.syslog
kuing.txt
log.out
mimi
[root@localhost ~]# ls | grep ‘n*‘ ‘n*‘和‘a*‘效果都是一样的。
aaa
anaconda-ks.cfg
install.log
install.log.syslog
kuing.txt
log.out
mimi
匹配含a的,这里至少有一个a
[root@localhost ~]# ls | grep ‘aa*‘
aaa
anaconda-ks.cfg
install.log
install.log.syslog
[root@localhost ~]#
下面这句是 匹配里面至少有一个A,a可以出现0次或者n次的文件名。
[root@localhost mimi]# ls
a A Aa Aaa ab Ab abc ba hk tf tfh
[root@localhost mimi]# ls | grep ‘Aa*‘
A
Aa
Aaa
Ab
验证 ‘mi*’和 ‘im*’的不同
[root@localhost ~]# ls
aaa anaconda-ks.cfg install.log install.log.syslog kuing.txt log.out mimi
[root@localhost ~]#
[root@localhost ~]# ls | grep ‘mi*‘
mimi
[root@localhost ~]# ls | grep ‘im*‘
install.log
install.log.syslog
kuing.txt
mimi
---------------------------------
本文出自 “kuing home pages” 博客,请务必保留此出处http://kuing.blog.51cto.com/9635522/1684629
标签:linux grep *
原文地址:http://kuing.blog.51cto.com/9635522/1684629