标签:dbus fsm 空格 stat apm 正则 modprobe info int
这篇文章主要用来介绍通配符,由于自己经常和正则表达式搞混,所以特地写了这篇文章,来梳理一些。
通配符主要匹配文件名,而正则主要匹配文件中的内容;
主要有* 、?、[]这三种;
? 匹配任意单个字符
如a?b,与之匹配的可以是aab,abb,a1b,a2b......
[] 匹配指定范围内的任意单个字符
如[wang] 即匹配w、a、n、g等任意一个字符;
[^] 匹配指定范围以外的任意单个字符
如[^wang] 排除列表中的所有字符,i与[]相反,即取反;
注意:对于下面的字符集,如果想要表示其中任意一个字符,需要在外面再加一个[]才可以;
[0-9]: 任意数字
[a-z]: 注意,这里不仅仅是小写字母,而是a,A ,b,B,c,C...z这样的顺序,即:小写、大写
[A-Z]: 注意,这里不仅仅表示大写字母,而是A,b,B,c,C...z,Z的 顺序
[:digit:]:任意数字,相当于0-9
[:lower:]:任意小写字母
[:upper:]: 任意大写字母
[:alpha:]: 任意大小写字母
[:alnum:]:任意数字或字母
[:blank:]:水平空白字符
[:space:]:水平或垂直空白字符,包含空格
[:punct:]:标点符号
更多内容,可以man 7 glob查看
(1)环境准备:
[root@CentOS6 var ]#touch l2223343434a
[root@CentOS6 var ]#touch l22233sddfd34a
[root@CentOS6 var ]#touch l22dfdf34a
(2)方法一:
[root@CentOS6 var ]#ls /var/l*[[:digit:]]*[[:lower:]]
/var/l2223343434a /var/l22233sddfd34a /var/l22dfdf34a
或
[root@CentOS6 var ]#ls -d /var/l*[0-9]*[[:lower:]]
/var/l2223343434a /var/l22233sddfd34a /var/l22dfdf34a
(1)准备环境:
[root@CentOS6 var ]#touch /etc/133rdfdf
[root@CentOS6 var ]#touch /etc/123xin
[root@CentOS6 var ]#touch /etc/123yuanhonli
[root@CentOS6 var ]#touch /etc/abc_xn
[root@CentOS6 var ]#touch /etc/1axc_xn
(2)解答:
[root@CentOS6 var ]#ls /etc/[0-9]*[^0-9]
/etc/123xin /etc/123yuanhonli /etc/133rdfdf /etc/1axc_xn
或
[root@CentOS6 var ]#ls /etc/[0-9]*[^[:digit:]]
/etc/123xin /etc/123yuanhonli /etc/133rdfdf /etc/1axc_xn
(1准备环境:
[root@CentOS6 var ]#touch /etc/1axc_xn
[root@CentOS6 var ]#touch /etc/_222b
[root@CentOS6 var ]#touch /etc/*b22b
[root@CentOS6 var ]#touch /etc/xinb22b
(2)解答:
[root@CentOS6 var ]#ls /etc/[^[:alpha:]][[:alpha:]]*
/etc/1axc_xn /etc/*b22b
解答:
[root@CentOS6 var ]#ls -d /etc/rc[0-6]* ##注意添加-d选项,否则显示所有目录下的文件
/etc/rc0.d /etc/rc1.d /etc/rc2.d /etc/rc3.d /etc/rc4.d /etc/rc5.d /etc/rc6.d
解答:
[root@CentOS6 var ]#ls -d /etc/*.d
/etc/bash_completion.d /etc/logrotate.d /etc/rc0.d /etc/rsyslog.d
/etc/chkconfig.d /etc/lsb-release.d /etc/rc1.d /etc/rwtab.d
/etc/cron.d /etc/makedev.d /etc/rc2.d /etc/sane.d
/etc/depmod.d /etc/modprobe.d /etc/rc3.d /etc/setuptool.d
/etc/dnsmasq.d /etc/oddjobd.conf.d /etc/rc4.d /etc/statetab.d
/etc/dracut.conf.d /etc/pam.d /etc/rc5.d /etc/sudoers.d
/etc/init.d /etc/popt.d /etc/rc6.d /etc/sysctl.d
/etc/latrace.d /etc/prelink.conf.d /etc/rc.d /etc/xinetd.d
/etc/ld.so.conf.d /etc/profile.d /etc/request-key.d /etc/yum.repos.d
[root@CentOS6 var ]#
解答:
[root@CentOS6 var ]#ls -d /etc/[mnrp]*.conf
/etc/mke2fs.conf /etc/ntp.conf /etc/prelink.conf /etc/rsyslog.conf
/etc/mtools.conf /etc/pbm2ppa.conf /etc/readahead.conf
/etc/nfsmount.conf /etc/pm-utils-hd-apm-restore.conf /etc/request-key.conf
/etc/nsswitch.conf /etc/pnm2ppa.conf /etc/resolv.conf
[root@CentOS6 var ]#ls -d /root/.*
/root/. /root/.cache /root/.gnote /root/.local /root/.thumbnails
/root/.. /root/.config /root/.gnupg /root/.nautilus /root/.viminfo
/root/.abrt /root/.cshrc /root/.gtk-bookmarks /root/.pulse /root/.Xauthority
/root/.bash_history /root/.dbus /root/.gvfs /root/.pulse-cookie
/root/.bash_logout /root/.esd_auth /root/.ICEauthority /root/.ssh
/root/.bash_profile /root/.gconf /root/.icons /root/.tcshrc
/root/.bashrc /root/.gnome2 /root/.imsettings.log /root/.themes
[root@CentOS6 var ]#
解答:
[root@CentOS6 var ]#ls -d /etc/[^.]*
/etc/123xin /etc/host.conf /etc/prelink.cache
/etc/123yuanhonli /etc/hosts /etc/prelink.conf
/etc/133rdfdf /etc/hosts.allow /etc/prelink.conf.d
/etc/1axc_xn /etc/hosts.deny /etc/printcap
/etc/_222b /etc/hp /etc/profile
/etc/abc_xn /etc/httpd /etc/profile.d
/etc/abrt /etc/idmapd.conf /etc/protocols
标签:dbus fsm 空格 stat apm 正则 modprobe info int
原文地址:http://blog.51cto.com/13668904/2160984