Add to Favourites Add to Favourites    Print this Article Print this Article

Creating and applying a patch to a file

What's a patch?  Say you've got a file, let's use the /etc/exim.conf as an example, and you need to make changes to that file many times over.
This may be the case if you have many servers, and you want all of them to have the same changes made.
The best way to make the same changes to the exim.conf, but to also allow the default exim.conf to have differences in other areas, is to use a patch.


Creating a patch

1) To create a patch, first copy your original:

cd /etc
cp exim.conf exim.conf.orig


2) Now manually make all the changes you want to your exim.conf:

nano exim.conf


3) Create the patch:

diff -u exim.conf.orig exim.conf > exim.conf.patch


You've now got a patch file which can be applied to the original exim.conf for other systems, or if you re-install, etc..
Save it to a location on your website so it can be downloaded to other servers.



Applying your patch

You've got a patch file, and your default exim.conf, and your want your changes to be applied.

4) Save the patch beside the file:

cd /etc/
wget http://your.server.com/exim.conf.patch


5) Apply the patch:

patch -p0 < exim.conf.patch

and you're done.

Your patched exim.conf should now have all of the changes that were manually done to the original.

Was this answer helpful?

Also Read