简体   繁体   English

我的查找排除路径命令有什么问题?

[英]What is wrong with my find exclude path command?

My folder我的文件夹

app
data
node_modules
package.json
package-lock.json
server

I want to exclude node_modules我想排除 node_modules

find . -path node_modules -prune -o -type f -name "package.json"

and serach name in all other paths.并在所有其他路径中搜索名称。 But I got但我得到了

./node_modules/postcss-pseudo-class-any-link/package.json
./node_modules/postcss-pseudo-class-any-link/node_modules/cssesc/package.json
./node_modules/postcss-pseudo-class-any-link/node_modules/postcss-selector-parser/package.json
./node_modules/normalize-range/package.json
./node_modules/run-queue/package.json
./node_modules/regenerator-runtime/package.json

and so on等等

Why?为什么?

Use name instead of path .使用name而不是path Also, you should explicitly -print to avoid an implicit print of the directory that is being pruned.此外,您应该显式地 -print 以避免隐式打印正在修剪的目录。

find . -name node_modules -prune -o -type f -name package.json -print

Note that your use of quotes is curious.请注意,您对引号的使用很奇怪。 For consistency, it seems to me that you ought to write:为了一致性,在我看来你应该写:

find "." "-name" "node_modules" "-prune" "-o" "-type" "f" "-name" "package.json" "-print"

or even甚至

"find" "." "-name" "node_modules" "-prune" "-o" "-type" "f" "-name" "package.json" "-print".

If you're going to quote one argument, you might as well quote them all.如果你要引用一个论点,你不妨引用它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM