Linux通配符 說明:通配符是bash的內置功能,幾乎適用於全部Linux命令。 * 匹配任意(0個或多個)字符或字符串,包括空字符串。 ? 匹配任意1個字符,有且只有一個字符。 [abcd] 匹配abcd中任何一個字符,abcd也能夠是其餘任意不連續字符。 [a-z] 匹配a到z之間的任意一個字符,字符先後要連續,也能夠用連續數字,即[1-9]。 [!abcd] 表示不匹配括號裏面的任何一個字符,也能夠寫爲 [!a-d],這裏的 "!"號能夠用"^" 替代,即[^abcd] 通配符"*" 示例: [root@testdb62 test]# touch exec.sh liang.log guo.log liang.sql a.sql [root@testdb62 test]# ls a.sql exec.sh guo.log liang.log liang.sql 查看全部結尾爲 log 結尾的文件 [root@testdb62 test]# ls *.log guo.log liang.log 查看全部結尾爲 sh 結尾的文件 [root@testdb62 test]# ls *.sh exec.sh 通配符"?" 示例: [root@testdb62 test]# ls ?.sh ls: 沒法訪問?.sh: 沒有那個文件或目錄 [root@testdb62 test]# touch a.sh [root@testdb62 test]# ls ?.sh a.sh [root@testdb62 test]# ls ???.sh ls: 沒法訪問???.sh: 沒有那個文件或目錄 [root@testdb62 test]# ls ???.log guo.log 通配符"[abcd]" 示例: [root@testdb62 test]# ls [abcd].sh a.sh [root@testdb62 test]# ls gu[opq].log guo.log 通配符"[a-z]" 示例: [root@testdb62 test]# touch c.sh d.sh cd.sh [root@testdb62 test]# ls a.sh cd.sh c.sh d.sh exec.sh guo.log liang.log liang.sql [root@testdb62 test]# ls [a-z].sh a.sh c.sh d.sh [root@testdb62 test]# ls [a-z]???.sh exec.sh [root@testdb62 test]# touch 1 [root@testdb62 test]# touch 2 [root@testdb62 test]# ls [1-9] 1 2 通配符"[!abcd]" 示例: [root@testdb62 test]# touch a b c d e f [root@testdb62 test]# ls [^abcd] 1 2 e f [root@testdb62 test]# ls 1 2 a a.sh b c cd.sh c.sh d d.sh e exec.sh f guo.log liang.log liang.sql [root@testdb62 test]# ls [!abcd] 1 2 e f [root@testdb62 test]# ls [!a-d] 1 2 e f [root@testdb62 test]# ls [^1-9] a b c d e f