Shell中的通配符

  shell常見的通配符,注意與正則稍有不一樣:shell

字符 含義 實例
* 匹配0個或多個任意字符

a*b,a與b之間能夠有任意長度的字符,也能夠沒有。blog

例如:aabcb,ab,azxcb...字符串

? 匹配一個任意字符

a?b,a與b之間必須但也只能存在一個字符,該字符能夠是任意字符。string

例如:aab,abb,acb...it

[list] 匹配list中的任意單個字符

a[xyz]b,a與b之間必須但也只能存在一個字符,該字符只能是x或y或z。console

例如:axb,ayb,azbtable

[!list] 匹配除list中的任意單個字符

a[!a-z]b,a與b之間必須但也只能存在一個字符,該字符不能是小寫字母。class

例如:aAb,a0b...file

[c1-c2] 匹配c1-c2間的任意單個字符

a[0-1]b,a與b之間必須但也只能存在一個字符,該字符只能是數字。aop

例如:a0b,a1b...

{string1,string2,...} 匹配string一、string2等中的一個字符串

a{abc,xyz,opq}b,a與b之間必須但也只能存在一個字符串,字符串只能是abc或xyz或opq。

例如:aabcb,axyzb,aopqb...

  實例:

[root@youxi1 ~]# ls /etc/*.conf
/etc/asound.conf  /etc/kdump.conf      /etc/man_db.conf    /etc/sudo-ldap.conf
/etc/chrony.conf  /etc/krb5.conf       /etc/mke2fs.conf    /etc/sysctl.conf
/etc/dracut.conf  /etc/ld.so.conf      /etc/nsswitch.conf  /etc/vconsole.conf
/etc/e2fsck.conf  /etc/libaudit.conf   /etc/resolv.conf    /etc/yum.conf
/etc/fuse.conf    /etc/libuser.conf    /etc/rsyslog.conf
/etc/GeoIP.conf   /etc/locale.conf     /etc/sestatus.conf
/etc/host.conf    /etc/logrotate.conf  /etc/sudo.conf
[root@youxi1 ~]# ls /etc/???.conf
/etc/yum.conf
[root@youxi1 ~]# touch file{1,2,3}
[root@youxi1 ~]# ls file*
file1  file2  file3
[root@youxi1 ~]# ls file[123]
file1  file2  file3
相關文章
相關標籤/搜索