美文网首页
Linux通配符知识入门详解

Linux通配符知识入门详解

作者: slixiaohui | 来源:发表于2018-01-02 10:41 被阅读79次

欢迎访问我的个人博客:https://xiaohuilee.github.io/

注意:通配符和正则表达式是不一样的,因此代表的意义也是有较大区别的。

通配符一般用户命令行bash环境,而Linux正则表达式用于grep,sed,awk场景。

* -- 通配符,代表任意(0到多个)字符*****
? -- 通配符,代表任意1个字符
; -- 连接不同命令的分隔符*****
# -- 配置文件注释*****
| -- 管道*****
~ -- 用户的家目录*****
- -- 上一次所在的目录*****
$ -- 变量前需要加的符号
/ -- 路径分隔符号,也是根的意思
>或1> -- 重定向,覆盖*****
>> -- 追加重写向,追加内容文件尾部 *****
< -- 输入重定向*****(xargs,tr)
<< -- 追加输入重定向
'' -- 单引号,不具有变量置换功能,输出时所见即所得 *****
""-- 双引号,具有变量置换功能,解析变量后输出,什么都不加一般跟加了""差不多(如果是命令需要用`命令`或者$(命令))*****
`` -- tab键上面的键,反引号,两个``中间的为命令,会先执行等价$( ) *****
{} -- 中间为命令区块组合或者内容序列
! -- 逻辑运算中的“非”(not)
&& -- and 并且 当前一个指令执行成功时,执行后一个指令
|| --  or 或者 当前一个指令执行失败时,执行后一个指令   

1、常用例子:

[root@centos6 test]# touch {a,b,abc}.sh
[root@centos6 test]# ll
total 0
-rw-r--r-- 1 root root 0 Dec 31 11:07 abc.sh
-rw-r--r-- 1 root root 0 Dec 31 11:07 a.sh
-rw-r--r-- 1 root root 0 Dec 31 11:07 b.sh
[root@centos6 test]# ls *.sh
abc.sh  a.sh  b.sh
[root@centos6 test]# ls ?.sh
a.sh  b.sh
[root@centos6 test]# ls ???.sh
abc.sh
[root@centos6 test]# pwd;ls
/root/test
abc.sh  a.sh  b.sh
[root@centos6 test]# ls -l|grep a
total 0
-rw-r--r-- 1 root root 0 Dec 31 11:07 abc.sh
-rw-r--r-- 1 root root 0 Dec 31 11:07 a.sh
[root@centos6 test]# echo $LANG
en_US.UTF-8
[root@centos6 test]# echo 'date'
date
[root@centos6 test]# echo "date"
date
[root@centos6 test]# echo "`date`"
Sun Dec 31 11:42:08 CST 2017
[root@centos6 test]# echo "$(date)"
Sun Dec 31 11:42:25 CST 2017
[root@centos6 test]# echo date
date
[root@centos6 test]# echo `date`
Sun Dec 31 11:50:21 CST 2017

2、详细说明''单引号和""双引号的区别:

[root@centos6 test]# echo oldboy >a.txt
[root@centos6 test]# grep oldboy a.txt
oldboy
[root@centos6 test]# a=oldboy  
[root@centos6 test]# grep "$a" a.txt
oldboy
[root@centos6 test]# grep '$a' a.txt   
[root@centos6 test]# echo $a >>a.txt
[root@centos6 test]# cat a.txt
oldboy
oldboy
[root@centos6 test]# echo '$a' >>a.txt
[root@centos6 test]# cat a.txt
oldboy
oldboy
$a

3、{}内容序列举例,常见用法举例

[root@centos6 test]# echo file{1,2,3}
file1 file2 file3
[root@centos6 test]# echo file{1..3}
file1 file2 file3
[root@centos6 test]# echo file_{a..e}
file_a file_b file_c file_d file_e
备注:seq只能是数字的序列,这里可以是字母序列
[root@centos6 test]# cp a.sh{,.bak} 
[root@centos6 test]# ll
total 0
-rw-r--r-- 1 root root 0 Dec 31 11:07 a.sh
-rw-r--r-- 1 root root 0 Dec 31 12:23 a.sh.bak
备注:备份的特殊用法
[root@centos6 /]# mkdir /data/{3306,3307}/data -p
[root@centos6 /]# tree /data
/data
├── 3306
│   └── data
└── 3307
    └── data

4 directories, 0 files

相关文章

网友评论

      本文标题:Linux通配符知识入门详解

      本文链接:https://www.haomeiwen.com/subject/jfdfnxtx.html