linux通配符

主要用于匹配文件和目录  如果是内容需要用更复杂得正则

* 匹配 0个或者多个任意字符

? 匹配一个字符

[-] 匹配括号中任意一个字符 -代表范围 如a-z  A-Z 0-9 

[^] 匹配不是括号中的一个字符  如 [^a-9] 匹配不是0-9的字符

[root@localhost ~]# ls
anaconda-ks.cfg  lnmp1.6.tar.gz  lnmp-install.log  post_install.log  test
[root@localhost ~]# cd test
[root@localhost test]# touch dya dyb dyc dyabc dy1 dy2 dy3 dy55 dydd
[root@localhost test]# ls
dy1  dy2  dy3  dy55  dya  dyabc  dyb  dyc  dydd
[root@localhost test]# ls dy*
dy1  dy2  dy3  dy55  dya  dyabc  dyb  dyc  dydd
[root@localhost test]# ls dy[a-z]
dya  dyb  dyc
[root@localhost test]# ls[^a-z]
bash: ls[^a-z]: 未找到命令
[root@localhost test]# ls [^a-z]
ls: 无法访问[^a-z]: 没有那个文件或目录
[root@localhost test]# ls dy[^a-z]
dy1  dy2  dy3
[root@localhost test]# ls dy?
dy1  dy2  dy3  dya  dyb  dyc
[root@localhost test]# ls dy[a-z]*
dya  dyabc  dyb  dyc  dydd
[root@localhost test]# ls dy[a-z][a-z]
dydd
[root@localhost test]# 

单引号所有特殊符号丧失含义

双引号 $符号会解析

反引号会执行命令  可以用$()替换

转义特殊符号

[root@localhost test]# echo $name
test
[root@localhost test]# echo '$name'
$name
[root@localhost test]# echo "$name"
test
[root@localhost test]# a=`ls`
[root@localhost test]# echo $a
dy1 dy2 dy3 dy55 dya dyabc dyb dyc dydd
[root@localhost test]#
[root@localhost test]# b=$(ls)
[root@localhost test]# echo $b
dy1 dy2 dy3 dy55 dya dyabc dyb dyc dydd
[root@localhost test]# 
[root@localhost test]# echo $b
dy1 dy2 dy3 dy55 dya dyabc dyb dyc dydd
[root@localhost test]# echo $b
$b

  


  

  

原文地址:https://www.cnblogs.com/brady-wang/p/12820673.html