我正在尝试在我的项目的子目录中查找所有 javascript 文件。
工作树如下:
.
??? app
??? assets
??? components
??? email.txt
??? gulpfile.js
??? node_modules
??? package.json
Run Code Online (Sandbox Code Playgroud)
为此我说:
find . -name *.js
Run Code Online (Sandbox Code Playgroud)
或者
find . -path *.js
Run Code Online (Sandbox Code Playgroud)
奇怪的是,第一个命令只报告gulpfile.js
,而第二个命令什么都不报告。但是我有.js
文件app
,components
和node_modules
! 他们为什么不出现?
将单引号放在*.js
. 如果没有引号,shell 会将通配符扩展为与当前目录匹配的文件名,因此find
只会获取当前目录或 find 规范中的子目录中的那些文件名(但永远不会看到通配符)。要将其指定为模式以find
供使用,您需要防止外壳扩展。'*.js'
这样做。