通配符顾名思义就是通用的匹配信息的符号,比如星号(*)就是代表匹配零个或多个字符,问号(?)是代表匹配单个字符,中括号内加上数字[0-9]代表匹配单个阿拉伯数字的字符,而中括号内加上字母[abc]则是代表匹配单个指定的英文字母。俗话讲百闻不如一见,看书不如做实验,例如匹配下所有在/dev目录中且以sda开头的文件吧:
[[email protected] ~]# ls -l /dev/sda
brw-rw----. 1 root disk 8, 0 Jun 8 19:38 /dev/sda
[[email protected] ~]# ls -l /dev/sda1
brw-rw----. 1 root disk 8, 1 Jun 8 19:38 /dev/sda1
[[email protected] ~]# ls -l /dev/sda2
brw-rw----. 1 root disk 8, 2 Jun 8 19:38 /dev/sda2
[[email protected] ~]# ls -l /dev/sda3
ls: cannot access /dev/sda3: No such file or directory
[[email protected] ~]# ls -l /dev/sd*
brw-rw----. 1 root disk 8, 0 Jun 8 19:38 /dev/sda
brw-rw----. 1 root disk 8, 1 Jun 8 19:38 /dev/sda1
brw-rw----. 1 root disk 8, 2 Jun 8 19:38 /dev/sda2
[[email protected] ~]# ls -l /dev/sd(?)
bash: syntax error near unexpected token `(‘
[[email protected] ~]# ls -l /dev/sd?
brw-rw----. 1 root disk 8, 0 Jun 8 19:38 /dev/sda
[[email protected] ~]# ls -l /dev/sd??
brw-rw----. 1 root disk 8, 1 Jun 8 19:38 /dev/sda1
brw-rw----. 1 root disk 8, 2 Jun 8 19:38 /dev/sda2
[[email protected] ~]# ls -l /dev/s???
brw-rw----. 1 root disk 8, 1 Jun 8 19:38 /dev/sda1
brw-rw----. 1 root disk 8, 2 Jun 8 19:38 /dev/sda2
[[email protected] ~]# ls -l /dev/sda[0-9]
brw-rw----. 1 root disk 8, 1 Jun 8 19:38 /dev/sda1
brw-rw----. 1 root disk 8, 2 Jun 8 19:38 /dev/sda2
[[email protected] ~]# ls -l /dev/sd[a-z][0-9]
brw-rw----. 1 root disk 8, 1 Jun 8 19:38 /dev/sda1
brw-rw----. 1 root disk 8, 2 Jun 8 19:38 /dev/sda2