commands
patch — apply reviewed differences
Applies a patch to a target; can modify files. GNU --dry-run checks applicability without writing target, --batch --forward avoids prompts and reversed patches. Exit 0 when all hunks apply, 1 when some fail, 2 on more serious trouble. Use a disposable copy only. Example assumes a fresh search-transform lab fixture.
Formal Syntax & Structure
linux syntaxlinux
patch [OPTION]... [ORIGINAL [PATCHFILE]]Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| --dry-run | option | preview applicability |
| --batch | option | noninteractive |
| --forward | option | skip reversed patches |
| ORIGINAL | operand | explicit target |
| PATCHFILE | operand | reviewed patch |
Return Value
exit status and output
Applies a patch to a target; can modify files. GNU --dry-run checks applicability without writing target, --batch --forward avoids prompts and reversed patches. Exit 0 when all hunks apply, 1 when some fail, 2 on more serious trouble. Use a disposable copy only.
Working Example
Example Snippetlinux
cp old.txt work.txtpatch --dry-run --batch --forward work.txt < change.patchcmp -s work.txt old.txt && printf '%s\n' unchanged