π Normally βpatchβ is invoked like this:
patch <PATCHFILE
π The full format for invoking βpatchβ is:
patch OPTIONS... [ORIGFILE [PATCHFILE]]
π You can also specify where to read the patch from with the -i PATCHFILE or --input=PATCHFILE option. If you do not specify PATCHFILE, or if PATCHFILE is β-β, βpatchβ reads the patch (that is, the βdiffβ output) from the standard input.
π If you do not specify an input file on the command line, βpatchβ tries to intuit from the βleading textβ (any text in the patch that comes before the βdiffβ output) which file to edit. π Multiple Patches.
π By default, βpatchβ replaces the original input file with the patched version, possibly after renaming the original file into a backup file. πΎ Backup Names describes how βpatchβ names backup files. You can also specify where to put the output with the -o FILE or --output=FILE option; however, do not use this option if FILE is one of the input files.
| Use Case | Command | Description |
|---|---|---|
| Apply a patch from a file | patch < patchfile | Read patch from standard input or file with -i |
| Apply patch with backup | patch -b < patchfile | Back up original files before applying |
| Dry run (test without changes) | patch --dry-run < patchfile | Show results without modifying files |
| Reverse a patch | patch -R < patchfile | Assume old/new files swapped, undo a patch |
| Apply patch with fuzz factor | patch -F 3 < patchfile | Allow up to 3 lines of fuzz for inexact matches |
| Strip leading directories | patch -p1 < patchfile | Strip first component of file paths |
| Output to specific file | patch -o outputfile < patchfile | Write patched output to a file instead of in-place |
Here is a summary of all of the options that GNU βpatchβ accepts. π patch and Tradition for which of these options are safe to use in older versions of βpatchβ.
π Multiple single-letter options that do not take an argument can be combined into a single command line argument with only one dash.
-b --backup πΎ Backup the original contents of each file, even if backups would normally not be made. π Backups.-B PREFIX --prefix=PREFIX π Prepend PREFIX to backup file names. π Backup Names.--backup-if-mismatch πΎ Backup the original contents of each file if the patch does not exactly match the file. This is the default behavior when not conforming to POSIX. π Backups.--binary π’ Read and write all files in binary mode, except for standard output and /dev/tty. This option has no effect on POSIX-conforming systems like GNU/Linux. On systems where this option makes a difference, the patch should be generated by diff -a --binary. π Binary.-c --context π Interpret the patch file as a context diff. π patch Input.-d DIRECTORY --directory=DIRECTORY π Make directory DIRECTORY the current directory for interpreting both file names in the patch file, and file names given as arguments to other options. π patch Directories.-D NAME --ifdef=NAME π Make merged if-then-else output using NAME. π If-then-else.--dry-run π§ͺ Print the results of applying the patches without actually changing any files. π Dry Runs.-e --ed π Interpret the patch file as an ed script. π patch Input.-E --remove-empty-files ποΈ Remove output files that are empty after the patches have been applied. π Creating and Removing.-f --force πͺ Assume that the user knows exactly what he or she is doing, and do not ask any questions. π patch Messages.-F LINES --fuzz=LINES π Set the maximum fuzz factor to LINES. π Inexact.-g NUM --get=NUM π If NUM is positive, get input files from a revision control system as necessary; if zero, do not get the files; if negative, ask the user whether to get the files. π Revision Control.--help β Output a summary of usage and then exit.-i PATCHFILE --input=PATCHFILE π₯ Read the patch from PATCHFILE rather than from standard input. π patch Options.-l --ignore-white-space β£ Let any sequence of blanks (spaces or tabs) in the patch file match any sequence of blanks in the input file. π Changed White Space.-n --normal π Interpret the patch file as a normal diff. π patch Input.-N --forward β‘οΈ Ignore patches that βpatchβ thinks are reversed or already applied. See also -R. π Reversed Patches.--no-backup-if-mismatch π« Do not back up the original contents of files. This is the default behavior when conforming to POSIX. π Backups.-o FILE --output=FILE π€ Use FILE as the output file name. π patch Options.-pNUMBER --strip=NUMBER βοΈ Set the file name strip count to NUMBER. π patch Directories.--posix β
Conform to POSIX, as if the POSIXLY_CORRECT environment variable had been set. π patch and POSIX.--quoting-style=WORD π¬ Use style WORD to quote names in diagnostics, as if the QUOTING_STYLE environment variable had been set to WORD. π patch Quoting Style.-r REJECT-FILE --reject-file=REJECT-FILE π« Use REJECT-FILE as the reject file name. π Reject Names.-R --reverse π Assume that this patch was created with the old and new files swapped. π Reversed Patches.-s --quiet --silent π€« Work silently unless an error occurs. π patch Messages.-t --batch π€ Do not ask any questions. π patch Messages.-T --set-time β° Set the modification and access times of patched files from timestamps given in context diff headers, assuming that the context diff headers use local time. π Patching Timestamps.-u --unified π Interpret the patch file as a unified diff. π patch Input.-v --version βΉοΈ Output version information and then exit.-V BACKUP-STYLE --version=control=BACKUP-STYLE πΎ Select the naming convention for backup file names. π Backup Names.--verbose π£οΈ Print more diagnostics than usual. π patch Messages.-x NUMBER --debug=NUMBER π Set internal debugging flags. Of interest only to βpatchβ patchers.-Y PREFIX --basename-prefix=PREFIX π Prepend PREFIX to base names of backup files. π Backup Names.-z SUFFIX --suffix=SUFFIX πΎ Use SUFFIX as the backup extension instead of .orig or ~. π Backup Names.-Z --set-utc π Set the modification and access times of patched files from timestamps given in context diff headers, assuming that the context diff headers use UTC. π Patching Timestamps.Generated by phpman v4.9.26-5-g7740029 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-08-20 19:38 @216.73.216.26
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)