0

i love find -execute but sometimes i would like to do more complex operations like running find -execute in all matching folders.

(e.g. run a script on all header files in a subdirectory tree for all base directories that were created after some date).

This can be accomplished with piping the output of one find into the next, like so:

find . -type d -newermt 2021-01-01 -name "src" -print0 \
| xargs0 -IDIR find DIR -type f -name "*.h" -exec sed -e 's|Copyright|©|g' -i {} ";"

However, it would be possible to call one find -execute from another.

Somdething like this:

find . -type d -newermt 2021-01-01 -name "src" -exec \
   find {}¹ -type f -name "*.h" -exec \
       sed -e 's|Copyright|©|g' -i {}² \
       +² \
   +¹

The obvious problem is to associate the placeholder ({}) and the expansion specifier (+, resp ;) with the correct find. In my code above i used the ¹ to indicate association with the 1st find and ² for the 2nd instance.

So my question is: is it possible to call one find from another (multiple layers) or must i use xargs for stacking multiple finds?

umläute
  • 6,472

0 Answers0