patch
developmentLinux/Unix
The patch command is one of the most frequently used commands in Linux/Unix-like operating systems. patch Apply a diff file to an original
Quick Reference
Command Name:
patch
Category:
development
Platform:
Linux/Unix
Basic Usage:
patch [options] [arguments]
Common Use Cases
Syntax
patch [options] [originalfile [patchfile]]
Options
Option | Description |
---|---|
-b, --backup |
Make backup files |
-B PREFIX, --prefix=PREFIX |
Prefix for backup file names |
-d, --directory=DIR |
Change to directory DIR first |
--dry-run |
Print results without modifying any files |
-E, --remove-empty-files |
Remove output files that become empty |
-f, --force |
Force; assume patches for older versions |
-F NUM, --fuzz=NUM |
Set the fuzz factor to NUM (default=2) |
-i PATCHFILE, --input=PATCHFILE |
Read patch from PATCHFILE instead of stdin |
-l, --ignore-whitespace |
Ignore whitespace changes in context |
-n, --normal |
Interpret the patch as a normal diff |
-N, --forward |
Ignore patches that appear to be reversed or already applied |
-o FILE, --output=FILE |
Output patched files to FILE |
-p NUM, --strip=NUM |
Strip NUM leading components from file names |
-r REJECTFILE, --reject-file=REJECTFILE |
Output rejects to REJECTFILE instead of *.rej files |
-R, --reverse |
Assume patches were created with old and new files swapped |
-s, --quiet, --silent |
Work silently unless an error occurs |
-t, --batch |
Skip prompts about applying patches |
-T, --set-time |
Set times of patched files to time of context in patch file |
-u, --unified |
Interpret the patch as a unified diff |
-v, --version |
Print version information and exit |
-V METHOD, --version-control=METHOD |
Use METHOD version control (numbered, existing, simple) |
--verbose |
Output extra information about the work being done |
-x NUM, --context=NUM |
Set number of context lines copied from old file to NUM (default=3) |
-Z, --set-utc |
Set times of patched files to UTC |
--help |
Display help and exit |
Examples
How to Use These Examples
The examples below show common ways to use the patch
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
# Basic Examples Basic
patch file.txt < changes.patch