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

NameTypeDescription
--dry-runoptionpreview applicability
--batchoptionnoninteractive
--forwardoptionskip reversed patches
ORIGINALoperandexplicit target
PATCHFILEoperandreviewed 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
Linux Reference