Published on

Using Find with Xargs

Authors

Today as a team we were working on one git repo which consisted of a tonne of folders which were like little repositories in their own right as they each had so much code and functionality. Many of these repos were nodejs based.

One of the most painful issues we had was this repo was very messily organized where many of the setup instructions for it were wrong or/and missing. One issue we kept running into is that the install scripts did not npm install any of the node modules for us. This resulted in part of the application starting up but failing as the required node modules could not be found.

To ease this a bit I wrote a little script which finds all package.json files and runs npm install in their containing folder:

find .. -not -path "*/node_modules/*" -name "package.json" -printf '%h\n' | xargs -I % sh -c 'echo ......%;npm --prefix % install %'