Chris
Chris

Reputation: 4080

Find directories by name where parent directory contains a certain filename

I'm trying to get a list of directories with the name vendor where the parent directory also contains a file with the name composer.json.

Some context:

For a simple backup script I want to exclude generated files/folders such as node_modules (generated by NPM) and vendor (generated by Composer).

I can simply exclude all folders with the name node_modules because it is almost certain that it was generated by NPM. Though, the vendor folder, created by Composer, is a very common name, so I want to check if there is a composer.json file in the parent directory. If there is then I can assume that the vendor folder was generated by Composer.

Is there an efficient way to achieve this?

Upvotes: 2

Views: 557

Answers (1)

This will work:

find -type d -name vendor -execdir test -e composer.json \; -print

Upvotes: 3

Related Questions