Apply Patch File using Patch Command
The “patch” command allows you to apply the changes in a patch file to the original file(s). To do that use the below command.
Command :
patch < patch_file_name
Or :
patch [options] original_file patch_file_name
To apply the hello.patch file to the original hello.c file, use this following command.
Command :
patch < hello.patch
Output :
This will modify the hello.c file to match the changes in the hello.patch file. After running this command, both hello.c and hello_new.c will have the same updated content.
The patch file contains the names of the files that need to be patched. When you run the patch command, it reads the patch file and applies the changes to the specified original file(s).
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