搜索路径时 ** 是如何工作的
我没有找到很多关于此的信息,据我所知它递归地匹配文件名和目录,但它是如何工作的?
I didn't find a lot of info about this, as far as I know it matches filenames and directories recursively, but how does it work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Glob-expression
**
用于匹配所有文件和零或更多目录和子目录。如果模式后面是/
,则仅目录和子目录匹配。这意味着在命令行上的路径名扩展模式中,它用于递归文件搜索。
根据您使用的外壳,需要启用它。在bash中,这是通过:
以下示例:
当心以下模式不递归地
**。txt
。这只是将两个单一星号球体的组合视为与*。TXT
相同的组合。注意: bash和zsh之间存在细微的差异,但总体而言,它的效果相同。
The glob-expression
**
is used to match all files and zero or more directories and subdirectories. If the pattern is followed by a/
, only directories and subdirectories match.This means that it is used in a recursive file-search during path-name expansion patterns on the command line.
Depending on the shell you use, it needs to be enabled. In bash this is done with:
Here are examples:
Beware that the following pattern does not work recursively
**.txt
. This is just seen as a combination of two single asterisk globs and is identical to*.txt
.Note: there are subtle differences between bash and zsh, but in general it works the same.