我的個人博客:https://lixiaohui.live
注意:通配符和正則表達(dá)式是不一樣的卫枝,因此代表的意義也是有較大區(qū)別的。
通配符一般用戶命令行bash環(huán)境罢荡,而Linux正則表達(dá)式用于grep,sed,awk場景屋厘。
* -- 通配符薯鳍,代表任意(0到多個)字符*****
? -- 通配符咖气,代表任意1個字符
; -- 連接不同命令的分隔符*****
# -- 配置文件注釋*****
| -- 管道*****
~ -- 用戶的家目錄*****
- -- 上一次所在的目錄*****
$ -- 變量前需要加的符號
/ -- 路徑分隔符號,也是根的意思
>或1> -- 重定向,覆蓋*****
>> -- 追加重寫向挖滤,追加內(nèi)容文件尾部 *****
< -- 輸入重定向*****(xargs,tr)
<< -- 追加輸入重定向
'' -- 單引號崩溪,不具有變量置換功能,輸出時所見即所得 *****
""-- 雙引號斩松,具有變量置換功能伶唯,解析變量后輸出,什么都不加一般跟加了""差不多(如果是命令需要用`命令`或者$(命令))*****
`` -- tab鍵上面的鍵惧盹,反引號乳幸,兩個``中間的為命令,會先執(zhí)行等價$( ) *****
{} -- 中間為命令區(qū)塊組合或者內(nèi)容序列
! -- 邏輯運算中的“非”(not)
&& -- and 并且 當(dāng)前一個指令執(zhí)行成功時钧椰,執(zhí)行后一個指令
|| -- or 或者 當(dāng)前一個指令執(zhí)行失敗時粹断,執(zhí)行后一個指令
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嫡霞、詳細(xì)說明''單引號和""雙引號的區(qū)別:
[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瓶埋、{}
內(nèi)容序列舉例,常見用法舉例
[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只能是數(shù)字的序列,這里可以是字母序列
[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