是否可以制作一个匹配当前目录和所有子目录中文件的 glob?
对于此目录结构:
.
|-- README.txt
|-- firstlevel.rb
`-- lib
|-- models
| |-- foo
| | `-- fourthlevel.rb
| `-- thirdlevel.rb
`-- secondlevel.rb
3 directories, 5 files
glob 将匹配:
firstlevel.rb
lib/secondlevel.rb
lib/models/thirdlevel.rb
lib/models/foo/fourthlevel.rb
For this directory structure:
.
|-- README.txt
|-- firstlevel.rb
`-- lib
|-- models
| |-- foo
| | `-- fourthlevel.rb
| `-- thirdlevel.rb
`-- secondlevel.rb
3 directories, 5 files
The glob would match:
firstlevel.rb
lib/secondlevel.rb
lib/models/thirdlevel.rb
lib/models/foo/fourthlevel.rb
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
看起来无法从 bash 完成,
如果您使用 zsh 则会
产生正确的结果。
否则你可以劫持 ruby 解释器(也可能是其他语言的解释器)
感谢 Chris 和 Gaius 的回答。
Looks like it can't be done from
bash
If you using
zsh
thenwill produce the correct result.
Otherwise you can hijack the
ruby
interpreter (and probably those of other languages)Thanks to Chris and Gaius for your answers.
在 Ruby 本身中:
In Ruby itself:
在 zsh 中,
**/*.rb
有效In zsh,
**/*.rb
works如果我错过了问题的真正要点,我深表歉意,但是,如果我使用 sh/bash/etc.,那么我可能会使用 find 来完成这项工作:
当在脚本中使用,find 更加灵活。
Apologies if I've missed the real point of the question but, if I was using sh/bash/etc., then I would probably use find to do the job:
Globs can get a bit nasty when used from within a script and find is much more flexible.