Cheatsheet and introduction to "globbing", a programming concept that involves the use of wildcards and special characters for matching and filtering.
(TOC generated by verb using markdown-toc)
We love contributors!
Pull requests to add documentation, links to tools, corrections or anything else are warmly accepted and gratefully appreciated!
Too busy to contribute directly, but still want to show your support? Please consider starring this project or tweeting about it!
The term "globbing", also referred to as "glob matching" or "filepath expansion", is a programming concept that describes the process of using wildcards, referred to as "glob patterns" or "globs", for matching file paths or other similar sets of strings.
Similar to regular expressions, but much simpler and limited in scope, glob patterns are defined using a combination of special characters, or wildcards, alongside literal (non-matching) characters. For example, the glob pattern *.txt
would match all files in a directory with a .txt
file extension.
Globbing syntax
TODO: describe wildcards vs. extended globbing, and segue to following sections
The commonly supported characters supported across globbing implementations for basic wildcard matching are *
, ?
and a simplified version of regex brackets for matching any of a given set of characters.
Although many different globbing implementations exist across a number of different languages and environments, the following table summarizes the most commonly supported basic globbing features.
Character | Description |
---|---|
* |
Matches any character zero or more times, except for / . |
** |
Matches any character zero or more times, including / . |
? |
Matches any character one time |
[abc] |
Matches any of the specified characters (in this case, a , b or c ) |
Special exceptions:
*
typically does not match dotfiles (file names starting with a .
) unless explicitly enabled by the user via options?
also typically does not match the leading dot/***/
is the same as /*/
)Implementations
Globbing is typically enabled using third-party libraries. A notable exception, bash, provides built-in support for basic globbing.
TODO: add list of implementations
Additional reading
In addition to wildcard matching, extended globbing describes the addition of more advanced matching features, such as:
TBC...
In simple cases, brace expansion appears to work the same way as the logical OR
operator. For example, (a|b)
will achieve the same result as {a,b}
.
Here are some powerful features unique to brace expansion (versus character classes):
a{1..3}b/*.js
expands to: ['a1b/*.js', 'a2b/*.js', 'a3b/*.js']
a{c,{d,e}}b/*.js
expands to: ['acb/*.js', 'adb/*.js', 'aeb/*.js']
TBC...
Visit the braces library for more examples and information about brace expansion.
TBC...
As described by the bash man page:
pattern | regex equivalent | matches |
---|---|---|
?(foo) |
(foo)? |
zero or one occurrence of the given patterns |
*(foo) |
(foo)* |
zero or more occurrences of the given patterns |
+(foo) |
(foo)+ |
one or more occurrences of the given patterns |
@(foo) |
(foo) * |
one of the given patterns |
!(foo) |
^(?:(?!(foo)$).*?)$ |
anything except one of the given patterns |
* Note that @
isn't a RegEx character.
Example implementations
POSIX character classes, or "bracket expressions", provide a way of defining regular expressions using something closer to plain english.
For example, the pattern [[:alpha:][:digit:]]
would match a1
, but not aa
.
TBC...
Example implementations
This section describes matching using regular expressions as it relates to globbing.
When regex character classes are used in glob patterns, with the exception of brace expansion ({a,b}
, {1..5}
, etc), most of the special characters convert directly to regex, so you can expect them to follow the same rules and produce the same results as regex.
For example, given the list: ['a.js', 'b.js', 'c.js', 'd.js', 'E.js']
:
[ac].js
: matches both a
and c
, returning ['a.js', 'c.js']
[b-d].js
: matches from b
to d
, returning ['b.js', 'c.js', 'd.js']
[b-d].js
: matches from b
to d
, returning ['b.js', 'c.js', 'd.js']
a/[A-Z].js
: matches and uppercase letter, returning ['a/E.js']
However, there is
Learn about [regex character classes][character-classes].
Given ['a.js', 'b.js', 'c.js', 'd.js', 'E.js']
:
(a|c).js
: would match either a
or c
, returning ['a.js', 'c.js']
(b|d).js
: would match either b
or d
, returning ['b.js', 'd.js']
(b|[A-Z]).js
: would match either b
or an uppercase letter, returning ['b.js', 'E.js']
As with regex, parentheses can be nested, so patterns like ((a|b)|c)/b
will work. But it might be easier to achieve your goal using brace expansion.
The following options are commonly available on various globbing implementations.
Option name | Description |
---|---|
extglob |
Enable extended globs. In addition to the traditional globs (using wildcards: * , * , ? and [...] ), extended globs add (almost) the expressive power of regular expressions, allowing the use of patterns like `foo/!(a |
dotglob |
Allows files beginning with . to be included in matches. This option is automatically enabled if the glob pattern begins with a dot. Aliases: dot (supported by: minimatch, micromatch) |
failglob |
report an error when no matches are found |
globignore |
allows you to specify patterns a glob should not match Aliases: ignore (supported by: minimatch, micromatch) |
globstar |
recursively match directory paths (enabled by default in minimatch and micromatch, but not in bash) |
nocaseglob |
perform case-insensitive pathname expansion |
nocasematch |
perform case-insensitive matching. Aliases: nocase (supported by: minimatch, micromatch) |
nullglob |
when enabled, the pattern itself will be returned when no matches are found. Aliases: nonull (supported by: minimatch, micromatch) |
WIP
Like regular expressions, glob patterns are a type of regular language that must first be interpreted by a computer program before any actual matching takes place. This introduces two areas of risk:
Interpreting patterns
TODO (The process of parsing and compiling a glob pattern into a regular expression...)
Performing matches
TODO (The process of matching the compiled regular expression against a set of strings)
Risks
Learn more about globbing.
Name | Programming language |
---|---|
bash-glob | JavaScript/node.js |
brace-expansion | JavaScript/node.js |
braces | JavaScript/node.js |
expand-brackets | JavaScript/node.js |
glob | JavaScript/node.js |
micromatch | JavaScript/node.js |
minimatch | JavaScript/node.js |
nanomatch | JavaScript/node.js |
The following concepts are similar to or include the concept of globbing:
1.globbing是什么? globbing表示通配符,BASH支持文件名通配。 2.globbing常用列表及使用心得 序号 符号 使用心得 1 ? 表示任意一个字符,注意与常规的正则表达式的区别。(正则中?表示可选的) 2 * 表示任意长度任意字符,与正则有差异。比如: globbing中a*表示以a开头,之后是任意长度字符(也就是说*无法作用于前面的a) 而正则中表示a出现>=0次。 从这
根据官方教程,在命令行中使用curl执行下面命令: curl -d '[{"firstname": "barack", "lastname": "obama"}, {"firstname": "mitt", "lastname": "romney"}]' -H 'Content-Type: application/json' http://127.0.0.1:5000/people 出现了如下错
Bash语言不支持正则表达式,而是通配的使用方式。sed awk 等工具支持正则表达式。 Bash itself cannot recognize Regular Expressions. Inside scripts, it is commands and utilities – such as sed and awk – that interpret RE’s. Bash does carry
什么是 Globing? https://www.techopedia.com/definition/14392/globbing Definition - What does Globbing mean? Globbing is the process of using wildcard characters to request or evaluate sets of files with
在linux中使用ls、cp、mv、rm等命令时可以使用文件通配符匹配操作多个文件。 匹配模式 *:匹配任意长度的任意字符 ?:匹配任意单个字符 []:匹配指定范围内的任意单个字符(文件通配不区分字母的大小写) [^]:匹配非制定范围内的任意单个字符 特殊格式 [[:upper:]] 匹配任意单个大写字母 [[:lower:]] 匹配任意单个小写字母 [[:alnum:]] 匹配任意单个数字
问题描述 (venv) h3d@h3d2102:~/lizheng/testFlask$ curl -v -X PUT http://127.0.0.1:5000/jobs/%7B%22workspace%22:%22123%22,%22start%22:123456,%22count%22:1,%22tid%22:%22asd8-wqenj0-92mm-mlasd-kf%22,%22qqlist
从 the documentation and examples开始,我一直试图在JDK7中使用新的全局功能 我可以得到globs,如“glob:*.dat”来处理 Files.walkFileTree(startingDir, finder); 示例,但我无法获得“**”语法工作.我想要创建一些像: matcher = FileSystems.getDefault().getPathMatche
我正在使用递归函数遍历根目录下的文件。我只想提取*.txt文件,但不想排除目录。现在,我的代码如下所示: val stream = Files.newDirectoryStream(head, "*.txt") 但是这样做将不会匹配任何目录,并且返回的iterator()是False。我使用的是Mac,所以我不想包含的噪音文件是.DS_STORE。如何让newDirectoryStream获取*.
Ambari上显示错误信息: 2017-11-06 13:01:00,618 - Will retry 65 time(s), caught exception: (u"Execution of 'curl --location-trusted -k --negotiate -u : -b /var/lib/ambari-agent/tmp/cookies/ad58a07f-ffbc-473f-
转载:http://blog.csdn.net/csupengu/article/details/20693427 加个-g或--globoff选项就ok了 curl -g 'http://test.com/‘
globbing文件名通配机制: Linux下一切皆文件,那么为了更好的管理文件,Shell提供了一组称为通配符的特殊符号,用于模式匹配,如文件名匹配、路径名搜索、字符串查找等;用户可以在作为命令参数的文件名中包含这些通配符,构成一个所谓的“模式串”,以在执行过程中进行模式匹配。所谓通配是指:显示以指定条件的文件。如显示/var文件下a开头的目录或文件,至于a后面是什么我们不管,因此我们可以使用l
linux shell通配符(globbing) 通配符是由shell处理的, 它只会出现在 命令的“参数”里(它不用在命令名称里, 也不用在操作符上)。当shell在“参数”中遇到了通配符时,shell会将其当作路径或文件名去在磁盘上搜寻可能的匹配:若符合要求的匹配存在,则进行代换(路径扩展);否则就将该通配符作为一个普通字符传递给“命令”,然后再由命令进行处理。总之,通配符 实际上就是一种sh
在线上服务器上执行下面的命令 curl -vo /dev/null 'http://120.52.72.46:80/fileshare3010.dfiles.eu/c3pr90ntcsf0/auth-1375626538db3c073c81647e872cab8f-210.186.189.166-676861082-146404525-guest/FS301-5/[EROBEAT]_Junjou_
一、glob简述 glob(globbing):bash中用于实现文件名“通配”。 二、常用通配符 1. * 匹配任意长度的任意字符。 例如:a*b 可以匹配到:ab,aab,a12b,asggb,... 不能匹配到:abc 2. ? 匹配单个任意字符。 例如:a?b 可以匹配到:a1b,agb,aab,...
globbing:文件名通配 元字符: *:匹配任意长度的任意字符 ?:匹配任意单个字符 []:匹配指定范围内的任意单个字符 [a-z]或者[a-z]或者[[:alpha:]]:匹配任意一个字母 [[:upper:]]:匹配任意一个大写字母 [[:lower:]]:匹配任意一个大写字母 [0-9]或者[[:digit:]]:匹配任意一个数字 [a-z0-9]或者[[:alnum:]]:匹配任意一个
原因window的command.exe不支持单引号,所以要处理一下命令:先转义双引号,然后把单引号改为双引号, 比如,命令: curl -X POST --data '{"jsonrpc":"2.0","method":"int_signAddress","params":["INT36qSQxM7Bt8TrRLL1XtBeXJXBUM52", "0xEB0F92067B76D19740EB81
我只需要在所有嵌套目录(包括 PWD)下匹配具有一个特定扩展名的文件,并使用“通配”的 BASH。 我不需要将所有嵌套目录下的所有文件与 shell 通配匹配,但不需要在 PWD 中匹配。 我需要使用 grep 以外的命令匹配文件,搜索所有文件扩展名的目录 我不需要只递归地 grep,而只需要在具有某些扩展名(复数)的文件中 适用于所有文件(不是我的问题)。 在 PWD 中不匹配。 返回重复文件。
通配符路由用于匹配多个路由。 它捕获当用户输入错误的URL并显示URL中的所有路由时有用的所有路由。 语法 (Syntax) Router.map(function() { this.route('catchall', {path: '/*wildcard'}); }); 通配符路由以星号(*)符号开头,如上面的语法所示。 例子 (Example) 以下示例指定具有多个URL段的通配符路由