Apply Patch File to a Source Code Tree
To apply the openvpn.patch file to the openvpn-2.3.2 source code directory, use the following command.
Command :
patch -p3 < openvpn.patch
This will apply all the changes from the patch file to the appropriate files and directories within the openvpn-2.3.2 source tree.
Output :
patching file openvpn-2.3.2/aclocal.m4
patching file openvpn-2.3.2/build/Makefile.in
patching file openvpn-2.3.2/build/msvc/Makefile.in
The `-p3` option tells the patch command to ignore the first 3 directory levels from the file paths listed in the patch file. This is necessary because the patch file contains full paths, like `/usr/src/openvpn-2.3.2/aclocal.m4`.
If you run the patch command from the `/usr/src` directory without `-p3`, it won’t work correctly. The `-p3` option makes patch ignore the `/usr/src/` part of the paths, so it can apply the changes to the right files within the openvpn-2.3.2 directory.
How to Run Patch Command in Linux?
Sometimes, you install software by compiling it from source code instead of using package managers like yum or apt-get. When a security fix is available for such software, you can’t just upgrade it like you normally would. Instead, you must download the security patch, apply it to the source code, and then recompile the software.
This article explains how to create and apply the diff and patch commands. A patch file contains the differences between two versions of the same file or source code. It is made using the diff command and applied using the patch command.
Run Patch Command in Linux
- Syntax of running patch command in Linux
- Application of the Patch File
- Options and descriptions for patch command
- Create a Patch File using diff
- Apply Patch File using Patch Command
- Create a Patch From a Source Tree
- Apply Patch File to a Source Code Tree
- Take a Backup before Applying the Patch using -b
- Validate the Patch without Applying (Dry-run Patch File)
- How to Undo/Reverse a Patch