Creating and applying a patch to a file

Enter Your Query:
Use '%' for wildcards and quotes for "exact phrases"

Top Level » System Level

Creating and applying a patch to a fileLast Modified: Apr 5, 2013, 6:55 pm
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/

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.

© 2018 JBMC Software, Suite 173  3-11 Bellerose Drive, St Albert, AB  T8N 1P7  Canada.  Mon-Fri 9AM-5PM MST