Options and descriptions for patch command
Options |
Descriptions |
---|---|
-p<n> or –strip=<n> |
Tells patch how many directory levels to remove from file paths in the patch file. Use this when the patch file has different directory paths than your current folder. |
-i <patch_file> or –input=<patch_file> |
Specifies the patch file to use. Use this if you don’t want to provide the patch file as a separate argument. |
-d <directory> or –directory=<directory> |
Tells patch the folder where the original file is located. Use this if the patch file doesn’t include the folder information. |
-R or –reverse |
Undoes changes made by a previous patch, reversing the patch. Use this to remove changes applied earlier. |
-N or –forward |
Applies the patch even if the original file is missing. |
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