Linux Terminal Command: patch
The patch command is an essential tool in File Manipulation & Viewing. In this tutorial, we will explore what patch does, look at everyday examples, and cover advanced options to supercharge your command-line workflow.
Concept & Explanation
The patch command applies modifications generated by the diff command to an original source file.
Common Options & Syntax
patch [options] [arguments]
Here are the most common flags used with patch:
- Simple Usage: Basic default commands.
- Detailed View: Shows diagnostic information.
- Advanced Actions: Can chain parameters for scripting.
1. Interactive Example (Simple)
Here is how most people run the command:
# Example
patch original.txt < patch.diff
What it does: Applies changes listed in ‘patch.diff’ to ‘original.txt’.
2. Power-User Example (Advanced)
For scripting and advanced diagnostics, use this configuration:
# Advanced
patch -R original.txt < patch.diff
What it does: Reverses the patch (-R), reverting ‘original.txt’ back to its state before the patch was applied.
⚙️ Warning & Common Pitfalls
[!WARNING] If the original file was modified after the diff was created,
patchcan fail or create temporary rejection files (.rej).
🔗 Related Commands
Here are some related posts on cli_tty1 you might want to check out:
- diff : Compare files line by line.