正则表达式元字符的运用
字符匹配:
*作用:匹配任意长度的任意字符
? 作用:匹配任意单个字符
[]:作用:匹配指定范围内的任意单个字符
特殊格式:
[a-z]、[A-Z]、[0-9]、[a-z0-9]
[[:upper:]]:匹配所有大写字母
[[:lower:]]:匹配所有小写字母
[[:alpha:]]:匹配所有字母
[[:digit:]]:匹配所有数字
[[:alnum:]]:匹配所有的字母和数字
[[:space:]]:匹配所有的空白字符
[[:punct:]]:匹配所有的标点符号
[^]作用:不匹配指定范围内(不匹配方括号内的)的字符
[^[:upper:]]
[^0-9]
案例:显示/etc目录下,以非字母开头,后面跟了一个字母以及其它任意长度任意字符的文件或目录
1.创建文件及目录
touch abc a2c 123 1b3
mkdir def d5f 456 4e6
2.进行查询
[root@host etc]# ls -ld /etc/[[:digit:]][[:alpha:]]*
-rw-r--r--. 1 root root 0 Oct 29 00:30 /etc/1b3
drwxr-xr-x. 2 root root 4096 Oct 29 00:30 /etc/4e6
或
[root@host etc]# ls -ld /etc/[^[:alpha:]][^[:digit:]]*
-rw-r--r--. 1 root root 0 Oct 29 00:24 /etc/1b3
drwxr-xr-x. 2 root root 4096 Oct 29 00:24 /etc/4e6