命令行通配符
命令行通配符:
一段例子:
[[email protected] ~]# ls /dev/sda
/dev/sda
[[email protected] ~]# ls /dev/sda1
/dev/sda1
[[email protected] ~]# ls /dev/sda2
/dev/sda2
[[email protected] ~]# ls /dev/sda3
ls: cannot access /dev/sda3: No such file or directory
通配符的作用在这里就是你不确定有多少个分区,分区号,他可以帮你确定
* 匹配0个或多个字符
? 匹配任意单个个字符
[0-9] 匹配范围内的数字
[abc] 匹配已给出的字符
实例:
[[email protected] ~]# ls /dev/sda*
/dev/sda /dev/sda1 /dev/sda2
[[email protected] ~]# ls /dev/sda?
/dev/sda1 /dev/sda2
[[email protected] ~]# ls /dev/sda[0-9]
/dev/sda1 /dev/sda2
[[email protected] ~]# ls /dev/sd[abc]
/dev/sda
[[email protected] ~]# ls /dev/sd[abc]?
/dev/sda1 /dev/sda2
[[email protected] ~]# ls /dev/sd[abc]*
/dev/sda /dev/sda1 /dev/sda2
另外bash还支持许多特殊字符扩展:
\(反斜杠) 转义后面单个字符
‘’(单引号) 转义所有字符
“”(双引号) 变量依然生效
``(反引号) 执行命令语句
变量生效:
[[email protected] ~]# Price=5
[[email protected] ~]# echo "Price is $Price"
Price is 5
但是想显示价格为$5,它又和变量冲突,现在就该使用转义字符 \ 反斜杠
[[email protected] ~]# echo "Price is $$Price"
Price is 6892Price
[[email protected] ~]# echo "Price is \$$Price"
Price is $5
使用单引号表示转义所有字符
[[email protected] ~]# echo ‘Price is \$$Price‘
Price is \$$Price
使用``来执行命令语句
[[email protected] ~]# echo `uname -a`
Linux Msl23-linux.com 3.10.0-123.el7.x86_64 #1
SMP Mon May 5 11:16:57 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux
[[email protected] ~]# echo `uname -r`
3.10.0-123.el7.x86_64