码迷,mamicode.com
首页 > 系统相关 > 详细

linux[基础]-10-命令行通配符[01]

时间:2017-08-22 18:46:07      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:作用   tor   双引号   nbsp   $$   dev   多少   .com   bash   

命令行通配符

命令行通配符:

                   一段例子:

                            [root@Msl23-linux ~]# ls /dev/sda

        /dev/sda

        [root@Msl23-linux ~]# ls /dev/sda1

        /dev/sda1

         [root@Msl23-linux ~]# ls /dev/sda2

        /dev/sda2

        [root@Msl23-linux ~]# ls /dev/sda3

        ls: cannot access /dev/sda3: No such file or directory

 

                   通配符的作用在这里就是你不确定有多少个分区,分区号,他可以帮你确定

 

      *                          匹配0个或多个字符

      ?                          匹配任意单个个字符

      [0-9]                   匹配范围内的数字

      [abc]                   匹配已给出的字符

 

                   实例:

                            [root@Msl23-linux ~]# ls /dev/sda*

        /dev/sda  /dev/sda1  /dev/sda2

        [root@Msl23-linux ~]# ls /dev/sda?

        /dev/sda1  /dev/sda2

        [root@Msl23-linux ~]# ls /dev/sda[0-9]

        /dev/sda1  /dev/sda2

        [root@Msl23-linux ~]# ls /dev/sd[abc]

        /dev/sda

        [root@Msl23-linux ~]# ls /dev/sd[abc]?

        /dev/sda1  /dev/sda2

        [root@Msl23-linux ~]# ls /dev/sd[abc]*

        /dev/sda  /dev/sda1  /dev/sda2

 

         另外bash还支持许多特殊字符扩展:

 

                   \(反斜杠)            转义后面单个字符

                   ‘’(单引号)           转义所有字符

                   “”(双引号)          变量依然生效

                   ``(反引号)           执行命令语句

 

                   变量生效:

                            [root@Msl23-linux ~]# Price=5

        [root@Msl23-linux ~]# echo "Price is $Price"

        Price is 5

 

                   但是想显示价格为$5,它又和变量冲突,现在就该使用转义字符 \ 反斜杠

                            [root@Msl23-linux ~]# echo "Price is $$Price"

        Price is 6892Price

        [root@Msl23-linux ~]# echo "Price is \$$Price"

        Price is $5

 

                  使用单引号表示转义所有字符

                            [root@Msl23-linux ~]# echo ‘Price is \$$Price‘

        Price is \$$Price

 

                   使用``来执行命令语句

                            [root@Msl23-linux ~]# 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

        [root@Msl23-linux ~]# echo `uname -r`

        3.10.0-123.el7.x86_64

 

         

linux[基础]-10-命令行通配符[01]

标签:作用   tor   双引号   nbsp   $$   dev   多少   .com   bash   

原文地址:http://www.cnblogs.com/msl23/p/7412812.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!