apply a code patch to subdirectories of each project

50 views Asked by At

I have over 10+ drupal websites and I need to apply a patch to each one. currently my patch resides in /home/201803.patch and my drupal websites is in the same folder. Currently I have to cd into each directory and then run the following command:

patch -p1 < ../201803.patch

but I want to just be able to do each one from the /home folder. I tried in the home folder:

patch -p1 subdirectory/ < 201803.patch

but that doesnt work. How can I patch from one directory above?

1

There are 1 answers

0
leymannx On

This is a question about Bash/Shell. Try the following. This will cd in every subdirectory of your current location and will then run the given command.

find . -maxdepth 1 -type d \( ! -name . \) -exec bash -c "cd '{}' && patch -p1 < ../201803.patch" \;

Or one by one:

cd subdirectory && patch -p1 < ../201803.patch && cd ..