# info > patch

---
type: CommandReference
command: patch
mode: info
section: 
source: info
---

## Quick Reference

- `patch < PATCHFILE` — apply patch from stdin
- `patch -i PATCHFILE` — read patch from file
- `patch -o FILE` — output patched version to FILE
- `patch -pN --strip=N` — strip N leading path components from filenames
- `patch -R --reverse` — reverse the patch
- `patch --dry-run` — test without modifying files
- `patch -b --backup` — back up original files unconditionally
- `patch -E --remove-empty-files` — remove empty output files after patching

## Name

patch — apply a diff file to an original file

## Synopsis

patch [OPTIONS...] [ORIGFILE [PATCHFILE]]
patch -i PATCHFILE [OPTIONS...] [ORIGFILE]
If no PATCHFILE is given, or if PATCHFILE is `-`, patch reads from standard input.  
If ORIGFILE is omitted, patch tries to intuit the file to edit from the patch leading text.

## Options

### Input / Output

- `-i PATCHFILE, --input=PATCHFILE` — read patch from PATCHFILE (default: stdin)
- `-o FILE, --output=FILE` — write patched file to FILE (do not use if FILE is an input file)
- `-r REJECT-FILE, --reject-file=REJECT-FILE` — write reject hunks to REJECT-FILE

### Patch Type (interpretation)

- `-c, --context` — treat patch as a context diff
- `-e, --ed` — treat patch as an `ed` script
- `-n, --normal` — treat patch as a normal diff
- `-u, --unified` — treat patch as a unified diff

### Backup Options

- `-b, --backup` — back up original files unconditionally
- `-B PREFIX, --prefix=PREFIX` — prepend PREFIX to backup filenames
- `-Y PREFIX, --basename-prefix=PREFIX` — prepend PREFIX to base names of backup files
- `-z SUFFIX, --suffix=SUFFIX` — use SUFFIX as backup extension (default: `.orig` or `~`)
- `-V BACKUP-STYLE, --version-control=BACKUP-STYLE` — select backup naming convention (see GNU Backup Names)
- `--backup-if-mismatch` — backup original if patch does not exactly match (default when not POSIX)
- `--no-backup-if-mismatch` — do not backup on mismatch (default when POSIX)

### Directory and Path Strip

- `-d DIRECTORY, --directory=DIRECTORY` — change to DIRECTORY before interpreting filenames
- `-pNUMBER, --strip=NUMBER` — strip NUMBER leading path components from patch filenames

### Behavior / Control

- `-f, --force` — assume user knows what they are doing; do not ask questions
- `-t, --batch` — do not ask any questions (implied by `-f`)
- `-s, --quiet, --silent` — work silently unless an error occurs
- `--verbose` — print more diagnostics than usual
- `-N, --forward` — ignore patches that appear reversed or already applied
- `-R, --reverse` — assume patch was created with old and new files swapped
- `-F LINES, --fuzz=LINES` — set maximum fuzz factor (allow inexact matching)
- `-l, --ignore-white-space` — ignore whitespace differences (sequences of blanks match)
- `-D NAME, --ifdef=NAME` — make merged if-then-else output using NAME
- `-E, --remove-empty-files` — delete output files that become empty after patching
- `-g NUM, --get=NUM` — if positive, get input files from revision control; if zero, do not; if negative, ask
- `-T, --set-time` — set modification/access times from context diff headers (local time)
- `-Z, --set-utc` — set modification/access times from context diff headers (UTC)
- `--binary` — read/write all files in binary mode (except stdout and /dev/tty)
- `--dry-run` — print the results of applying patches without changing any files
- `--posix` — conform to POSIX (as if `POSIXLY_CORRECT` is set)
- `--quoting-style=WORD` — use WORD to quote names in diagnostics (as if `QUOTING_STYLE` is set)

### Miscellaneous

- `--help` — display summary of usage and exit
- `-v, --version` — output version information and exit
- `-x NUMBER, --debug=NUMBER` — set internal debugging flags (for patch developers)

Multiple single-letter options that do not take an argument can be combined into one command-line argument (e.g., `-Rfs`).

## See Also

- [diff](https://www.gnu.org/software/diffutils/manual/)
- [diff3](https://www.gnu.org/software/diffutils/manual/)
- [sdiff](https://www.gnu.org/software/diffutils/manual/)
- [patch (GNU Diffutils)](https://www.gnu.org/software/diffutils/manual/)

## Exit Codes

Not documented in the source.