0

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?

0

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.