I have a folder structure as such:
我有一个文件夹结构:
a/
b/
test.js
c/
another_test.js
When I want to find all these files, I tried the globstar approach:
当我想找到所有这些文件时,我尝试了globstar方法:
ls a/{,**/}*.js
However, this command errors (but still outputs files) because there is no a/*.jsx
file:
但是,这个命令错误(但仍然输出文件),因为没有/ * .jsx文件:
$ ls a/{,**/}*.jsx
ls: a/*.jsx: No such file or directory
a/b/test.js
I want to use this specific glob because in the future, at some point, a/test.js
could exist.
我想使用这个特定的glob,因为在将来某个时候,/ test.js可能存在。
Is there a glob pattern that will find all .js
files in a/
recursively and not error?
是否有一个glob模式,可以在/递归中找到所有.js文件,而不是错误?
I looked at some of the options in this question but couldn't find anything that doesn't error and lists all files.
我查看了这个问题中的一些选项,但找不到任何错误并列出所有文件。
1 个解决方案
#1
With bash4 and above, just use:ls dir/**/*.js
使用bash4及更高版本,只需使用:ls dir / ** / * .js
With previous bash versions, such as 3.2 shipped with osx, you can use find:find dir -name '*.js'
使用以前的bash版本,例如3.2附带的osx,你可以使用find:find dir -name'* .js'
#1
With bash4 and above, just use:ls dir/**/*.js
使用bash4及更高版本,只需使用:ls dir / ** / * .js
With previous bash versions, such as 3.2 shipped with osx, you can use find:find dir -name '*.js'
使用以前的bash版本,例如3.2附带的osx,你可以使用find:find dir -name'* .js'