shell通配符

This commit is contained in:
sookie 2018-09-27 17:55:26 +08:00
parent 36b78d057a
commit fa6b11463e
4 changed files with 183 additions and 12 deletions

View File

@ -0,0 +1,58 @@
---
title: bash通配符
date: 2018-9-26 15:08:08
tags:
- linux
- shell
categories:
- linux
---
bash当中的通配符可以看做是原始的正则表达式
不如之后出现的正则表达式功能强大, 规则相对简单一些
可以在命令行或者shell编程当中使用
<!-- more -->
### ? 字符
代表任意的单个字符
比如
```bash
ls a?.txt
```
也就是筛选文件名是两个字符, 扩展名是txt, 且第一个字符为a的
### * 字符
代表任意数量的任意字符
比如
```bash
ls a*.txt
```
也就是筛选文件名第一个字符为a的, 扩展名是txt的文件
### [...] 模式
匹配方括号当中的任意 **一个字符**
或者一个连续的范围当中的 **一个字符**
```bash
# 匹配文件 ab.txt ac.txt
ls a[bc].txt
# 注意是 一个字符 , 所以abc.txt并不匹配
# 匹配文件 ab.txt ac.txt ad.txt
ls a[b-d].txt
```
连续范围根据字符编码确定
### [^...]和[!...]
表示匹配不在方括号当中的 **一个字符**
```bash
# 匹配文件 ac.txt ad.txt等
ls a[^b].txt
```
也可以使用连续的范围, 方式同上
### {...}模式
可以匹配大括号当中所有的模式, 模式之间用逗号分隔
```bash
ls a{a,b,c,d,ee}.txt
```
![shell通配符{}](/images/linux/shell通配符.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

137
yarn.lock
View File

@ -478,6 +478,10 @@ ee-first@1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
ejs@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/ejs/-/ejs-1.0.0.tgz#c9c60a48a46ee452fb32a71c317b95e5aa1fcb3d"
ejs@^2.3.4:
version "2.6.1"
resolved "https://registry.yarnpkg.com/ejs/-/ejs-2.6.1.tgz#498ec0d495655abc6f23cd61868d926464071aa0"
@ -665,6 +669,10 @@ has-unicode@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/has-unicode/-/has-unicode-2.0.1.tgz#e0e6fe6a28cf51138855e086d1691e771de2a8b9"
he@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/he/-/he-1.1.1.tgz#93410fd21b009735151f8868c2f271f3427e23fd"
hexo-bunyan@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/hexo-bunyan/-/hexo-bunyan-1.0.0.tgz#b2106b26547b232f0195db863cb5d5ff8527fd36"
@ -723,6 +731,22 @@ hexo-generator-archive@^0.1.4:
hexo-pagination "0.0.2"
object-assign "^2.0.0"
hexo-generator-baidu-sitemap@0.0.8:
version "0.0.8"
resolved "https://registry.yarnpkg.com/hexo-generator-baidu-sitemap/-/hexo-generator-baidu-sitemap-0.0.8.tgz#352b55d017cd1b2947ce9cd60af5c4dbebe880bb"
dependencies:
ejs "^1.0.0"
utils-merge "^1.0.0"
hexo-generator-baidu-sitemap@^0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/hexo-generator-baidu-sitemap/-/hexo-generator-baidu-sitemap-0.1.2.tgz#46521c35cda1666db2c7e50a14fc87c21a7d5634"
dependencies:
ejs "^1.0.0"
hexo "^3.0.0"
hexo-generator-baidu-sitemap "0.0.8"
utils-merge "^1.0.0"
hexo-generator-category@^0.1.3:
version "0.1.3"
resolved "https://registry.yarnpkg.com/hexo-generator-category/-/hexo-generator-category-0.1.3.tgz#b9e6a5862530a83bdd7da4c819c1b9f3e4ccb4b2"
@ -744,12 +768,21 @@ hexo-generator-index@^0.2.0:
hexo-pagination "0.0.2"
object-assign "^4.0.1"
hexo-generator-search@^2.2.5:
version "2.2.5"
resolved "https://registry.yarnpkg.com/hexo-generator-search/-/hexo-generator-search-2.2.5.tgz#624b16992a58d9382f51a8b144526cc7a08e1c9b"
hexo-generator-json-content@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/hexo-generator-json-content/-/hexo-generator-json-content-3.0.1.tgz#817cfcecbe9abd93041405f24060dbe93e984744"
dependencies:
nunjucks "^3.0.1"
utils-merge "^1.0.0"
hexo-util latest
keyword-extractor latest
moment latest
hexo-generator-sitemap@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/hexo-generator-sitemap/-/hexo-generator-sitemap-1.2.0.tgz#3018f8d7d1e2e42b3f71a65a7316ffcf583bc3f3"
dependencies:
minimatch "^3.0.0"
nunjucks "^2.3.0"
object-assign "^4.0.1"
hexo-generator-tag@^0.2.0:
version "0.2.0"
@ -814,7 +847,7 @@ hexo-server@^0.2.0:
opn "^4.0.0"
serve-static "^1.10.0"
hexo-util@^0.6.0, hexo-util@^0.6.2, hexo-util@^0.6.3:
hexo-util@^0.6.0, hexo-util@^0.6.2, hexo-util@^0.6.3, hexo-util@latest:
version "0.6.3"
resolved "https://registry.yarnpkg.com/hexo-util/-/hexo-util-0.6.3.tgz#16a2ade457bef955af0dfd22a3fe6f0a49a9137c"
dependencies:
@ -825,7 +858,15 @@ hexo-util@^0.6.0, hexo-util@^0.6.2, hexo-util@^0.6.3:
html-entities "^1.2.0"
striptags "^2.1.1"
hexo@^3.2.0:
hexo-wordcount@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/hexo-wordcount/-/hexo-wordcount-3.0.2.tgz#dbe15ba56913f0bce490b94f84c042629ebe672d"
dependencies:
html-to-text "^2.1.3"
numeral "^1.5.3"
wordcount "^1.1.1"
hexo@^3.0.0, hexo@^3.2.0:
version "3.7.1"
resolved "https://registry.yarnpkg.com/hexo/-/hexo-3.7.1.tgz#0381874e67891b521b9e3023ef4db85a62337f96"
dependencies:
@ -865,6 +906,16 @@ html-entities@^1.2.0:
version "1.2.1"
resolved "https://registry.yarnpkg.com/html-entities/-/html-entities-1.2.1.tgz#0df29351f0721163515dfb9e5543e5f6eed5162f"
html-to-text@^2.1.3:
version "2.1.3"
resolved "https://registry.yarnpkg.com/html-to-text/-/html-to-text-2.1.3.tgz#e50dbe4e4079912dbedcde05d278388edb8eea91"
dependencies:
he "^1.0.0"
htmlparser "^1.7.7"
optimist "^0.6.1"
underscore "^1.8.3"
underscore.string "^3.2.3"
htmlparser2@^3.9.1:
version "3.9.2"
resolved "https://registry.yarnpkg.com/htmlparser2/-/htmlparser2-3.9.2.tgz#1bdf87acca0f3f9e53fa4fcceb0f4b4cbb00b338"
@ -876,6 +927,10 @@ htmlparser2@^3.9.1:
inherits "^2.0.1"
readable-stream "^2.0.2"
htmlparser@^1.7.7:
version "1.7.7"
resolved "https://registry.yarnpkg.com/htmlparser/-/htmlparser-1.7.7.tgz#19e7b3997ff6fbac99ae5a7d2766489efe7e2d0e"
http-errors@~1.6.2:
version "1.6.3"
resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-1.6.3.tgz#8b55680bb4be283a0b5bf4ea2e38580be1d9320d"
@ -1019,6 +1074,13 @@ jsonparse@^1.2.0:
version "1.3.1"
resolved "https://registry.yarnpkg.com/jsonparse/-/jsonparse-1.3.1.tgz#3f4dae4a91fac315f71062f8521cc239f1366280"
keyword-extractor@latest:
version "0.0.15"
resolved "https://registry.yarnpkg.com/keyword-extractor/-/keyword-extractor-0.0.15.tgz#193157dc6230f1be81f3147567ee8f16267d8e27"
dependencies:
underscore "1.7.0"
underscore.string "2.3.3"
kind-of@^3.0.2:
version "3.2.2"
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.2.2.tgz#31ea21a734bab9bbb0f32466d893aea51e4a3c64"
@ -1122,6 +1184,12 @@ marked@^0.3.9:
version "0.3.19"
resolved "https://registry.yarnpkg.com/marked/-/marked-0.3.19.tgz#5d47f709c4c9fc3c216b6d46127280f40b39d790"
match-words@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/match-words/-/match-words-0.1.1.tgz#dcd3119e74a6a67be4304ca5cf926580e8e1a7af"
dependencies:
word-regex "^0.1.0"
math-random@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/math-random/-/math-random-1.0.1.tgz#8b3aac588b8a66e4975e3cdea67f7bb329601fac"
@ -1162,7 +1230,7 @@ mime@^1.3.4:
version "1.6.0"
resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1"
"minimatch@2 || 3", minimatch@^3.0.2, minimatch@^3.0.4:
"minimatch@2 || 3", minimatch@^3.0.0, minimatch@^3.0.2, minimatch@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
dependencies:
@ -1209,6 +1277,10 @@ moment-timezone@^0.5.14:
version "2.22.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.22.1.tgz#529a2e9bf973f259c9643d237fda84de3a26e8ad"
moment@latest:
version "2.22.2"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.22.2.tgz#3c257f9839fc0e93ff53149632239eb90783ff66"
morgan@^1.6.1:
version "1.9.0"
resolved "https://registry.yarnpkg.com/morgan/-/morgan-1.9.0.tgz#d01fa6c65859b76fcf31b3cb53a3821a311d8051"
@ -1331,7 +1403,19 @@ number-is-nan@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d"
nunjucks@^3.0.0, nunjucks@^3.0.1, nunjucks@^3.1.2:
numeral@^1.5.3:
version "1.5.6"
resolved "http://registry.npmjs.org/numeral/-/numeral-1.5.6.tgz#3831db968451b9cf6aff9bf95925f1ef8e37b33f"
nunjucks@^2.3.0:
version "2.5.2"
resolved "https://registry.yarnpkg.com/nunjucks/-/nunjucks-2.5.2.tgz#ea7d346e785b8a4874666c3cca9e18c577fba22c"
dependencies:
asap "^2.0.3"
chokidar "^1.6.0"
yargs "^3.32.0"
nunjucks@^3.0.0, nunjucks@^3.1.2:
version "3.1.2"
resolved "https://registry.yarnpkg.com/nunjucks/-/nunjucks-3.1.2.tgz#85945a66bb8239bb37ecef83dab4cc1f152aabb9"
dependencies:
@ -1380,7 +1464,7 @@ opn@^4.0.0:
object-assign "^4.0.1"
pinkie-promise "^2.0.0"
optimist@~0.6:
optimist@^0.6.1, optimist@~0.6:
version "0.6.1"
resolved "https://registry.yarnpkg.com/optimist/-/optimist-0.6.1.tgz#da3ea74686fa21a19a111c326e90eb15a0196686"
dependencies:
@ -1634,7 +1718,7 @@ source-map@~0.5.1:
version "0.5.7"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
sprintf-js@^1.0.2:
sprintf-js@^1.0.2, sprintf-js@^1.0.3:
version "1.1.1"
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.1.1.tgz#36be78320afe5801f6cea3ee78b6e5aab940ea0c"
@ -1789,6 +1873,25 @@ uglify-to-browserify@~1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/uglify-to-browserify/-/uglify-to-browserify-1.0.2.tgz#6e0924d6bda6b5afe349e39a6d632850a0f882b7"
underscore.string@2.3.3:
version "2.3.3"
resolved "https://registry.yarnpkg.com/underscore.string/-/underscore.string-2.3.3.tgz#71c08bf6b428b1133f37e78fa3a21c82f7329b0d"
underscore.string@^3.2.3:
version "3.3.4"
resolved "https://registry.yarnpkg.com/underscore.string/-/underscore.string-3.3.4.tgz#2c2a3f9f83e64762fdc45e6ceac65142864213db"
dependencies:
sprintf-js "^1.0.3"
util-deprecate "^1.0.2"
underscore@1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.7.0.tgz#6bbaf0877500d36be34ecaa584e0db9fef035209"
underscore@^1.8.3:
version "1.9.1"
resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.9.1.tgz#06dce34a0e68a7babc29b365b8e74b8925203961"
unpipe@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"
@ -1797,7 +1900,7 @@ upper-case@^1.1.1:
version "1.1.3"
resolved "https://registry.yarnpkg.com/upper-case/-/upper-case-1.1.3.tgz#f6b4501c2ec4cdd26ba78be7222961de77621598"
util-deprecate@~1.0.1:
util-deprecate@^1.0.2, util-deprecate@~1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
@ -1840,6 +1943,16 @@ window-size@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/window-size/-/window-size-0.1.4.tgz#f8e1aa1ee5a53ec5bf151ffa09742a6ad7697876"
word-regex@^0.1.0:
version "0.1.2"
resolved "https://registry.yarnpkg.com/word-regex/-/word-regex-0.1.2.tgz#a3bc7f2d222ce4a93c246c3ef69458f61f511639"
wordcount@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/wordcount/-/wordcount-1.1.1.tgz#e72da7833904d870a154c9ef47ed5f3e7997cf57"
dependencies:
match-words "^0.1.0"
wordwrap@0.0.2:
version "0.0.2"
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.2.tgz#b79669bb42ecb409f83d583cad52ca17eaa1643f"