Reputation: 2758
My folder
app
data
node_modules
package.json
package-lock.json
server
I want to exclude 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?
Upvotes: 0
Views: 43
Reputation: 212634
Use name
instead of path
. Also, you should explicitly -print to avoid an implicit print of the directory that is being pruned.
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.
Upvotes: 1