MikiBelavista
MikiBelavista

Reputation: 2758

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

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

Answers (1)

William Pursell
William Pursell

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

Related Questions