apply a code patch to subdirectories of each proje

2019-03-01 14:00发布

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条回答
相关推荐>>
2楼-- · 2019-03-01 14:33

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 ..

查看更多
登录 后发表回答