bash 使用bash终端命令打开目录和子目录中的所有文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29202889/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Open all files in a directory and subdirectories using bash terminal command?
提问by o_O
I have an alias where I can do open file1.type file2.type
or open *.type
我有一个别名,我可以在那里做open file1.type file2.type
或open *.type
What I want is to be able to use this on all subdirectories of my current location. So if I'm in the parent directory and there are two child directories, running the command will be the same as running open file1.type file2.type child1/file1.type child2/file1.type
我想要的是能够在我当前位置的所有子目录上使用它。因此,如果我在父目录中并且有两个子目录,则运行该命令将与运行相同open file1.type file2.type child1/file1.type child2/file1.type
So something like open -? *.type
is what I'm looking for.
所以open -? *.type
我正在寻找类似的东西。
回答by Ignacio Vazquez-Abrams
If running zsh or bash 4.x with the globstar
option set, **
will match all directories recursively.
如果使用globstar
设置的选项运行 zsh 或 bash 4.x ,**
将递归匹配所有目录。
#!/bin/zsh
open **/*.type
...
...
#!/bin/bash
shopt -s globstar
open **/*.type
回答by Paul Hicks
find
works for this sort of functionality. Something like this:
find
适用于这种功能。像这样的东西:
find . -type f -name \*.type -exec open {} \;
Or in this case, since open
is an alias, you have to run the shell as the command:
或者在这种情况下,由于open
是别名,您必须将 shell 作为命令运行:
find . -type f -name \*.type -exec bash -c open {} \;