lnlidawei

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

 

 

Linux 命令行中的通配符

 

 

 

 

 

 

 


一、通配符概述

 

  0、说明:   bash环境, 在“英文输入法”状态下操作;

 

  1、*      匹配“0”或多个字符; 字符数>=0

 

  2、?     匹配任意‘单个字符’


  3、[]    匹配范围内的‘单个字符’


  4、[^]     不匹配范围内的‘单个字符’


  5、[!]     不匹配范围内的‘单个字符’


  6、{}     匹配范围内的‘单个字符’或者‘字符串’


  7、\      转义单个字符(转义,将特殊字符编程普通字符)


  8、''     单引号,转义“单引号”中所有字符


  9、""     双引号,“双引号”内的变量依然有效


  10、``     反引号,执行命令语句

 

 

 

 

二、示例:

 

[root@rockylinux tmp]# touch   {a..e}{1..3}

 

[root@rockylinux tmp]# ls
a1 a2 a3 b1 b2 b3 c1 c2 c3 d1 d2 d3 e1 e2 e3

 

[root@rockylinux tmp]# ls   a?
a1 a2 a3

 

[root@rockylinux tmp]# ls   ?1
a1 b1 c1 d1 e1

 

[root@rockylinux tmp]# ls   [abcde]1
a1 b1 c1 d1 e1

 

[root@rockylinux tmp]# ls   a[123]
a1 a2 a3

 

[root@rockylinux tmp]# ls   {a?,b?,c?}
a1 a2 a3 b1 b2 b3 c1 c2 c3

 

[root@rockylinux tmp]# ls   a{1,2,3}
a1 a2 a3

 

[root@rockylinux tmp]# ls   [^a]?
b1 b2 b3 c1 c2 c3 d1 d2 d3 e1 e2 e3

 

[root@rockylinux tmp]# ls   [!a]?
b1 b2 b3 c1 c2 c3 d1 d2 d3 e1 e2 e3

 

[root@rockylinux tmp]# age=3

 

[root@rockylinux tmp]# echo    "I am $age."
I am 3.

 

[root@rockylinux tmp]# echo    'I am $age.'
I am $age.

 

[root@rockylinux tmp]# echo   hello\\tworld
hello\tworld

 

[root@rockylinux tmp]# echo    "hello\tworld"
hello\tworld

 

[root@rockylinux tmp]# echo   -e   "hello\tworld"
hello world

 

[root@rockylinux tmp]# echo   -e   'hello\tworld'
hello world

 

[root@rockylinux tmp]# echo   current_files: `ls`
current_files: a1 a2 a3 b1 b2 b3 c1 c2 c3 d1 d2 d3 e1 e2 e3


[root@rockylinux tmp]#
[root@rockylinux tmp]#

 

posted on 2022-06-09 05:27  lnlidawei  阅读(264)  评论(0编辑  收藏  举报