The patch utility shall conform to the Base Definitions volume of
POSIX.1‐2017, Section 12.2, Utility Syntax Guidelines.
The following options shall be supported:
-b
Save a copy of the original contents of each modified
file, before the differences are applied, in a file of
the same name with the suffix .orig
appended to it. If
the file already exists, it shall be overwritten; if
multiple patches are applied to the same file, the
.orig
file shall be written only for the first patch.
When the -o
outfile option is also specified, file.orig
shall not be created but, if outfile already exists,
outfile.orig
shall be created.
-c
Interpret the patch file as a copied context difference
(the output of the utility diff when the -c
or -C
options are specified).
-d
dir Change the current directory to dir before processing
as described in the EXTENDED DESCRIPTION section.
-D
define Mark changes with one of the following C preprocessor
constructs:
#ifdef define
...
#endif
#ifndef define
...
#endif
optionally combined with the C preprocessor construct
#else
. If the patched file is processed with the C
preprocessor, where the macro define is defined, the
output shall contain the changes from the patch file;
otherwise, the output shall not contain the patches
specified in the patch file.
-e
Interpret the patch file as an ed script, rather than a
diff script.
-i
patchfile
Read the patch information from the file named by the
pathname patchfile, rather than the standard input.
-l
(The letter ell.) Cause any sequence of <blank>
characters in the difference script to match any
sequence of <blank> characters in the input file. Other
characters shall be matched exactly.
-n
Interpret the script as a normal difference.
-N
Ignore patches where the differences have already been
applied to the file; by default, already-applied
patches shall be rejected.
-o
outfile
Instead of modifying the files (specified by the file
operand or the difference listings) directly, write a
copy of the file referenced by each patch, with the
appropriate differences applied, to outfile. Multiple
patches for a single file shall be applied to the
intermediate versions of the file created by any
previous patches, and shall result in multiple,
concatenated versions of the file being written to
outfile.
-p
num For all pathnames in the patch file that indicate the
names of files to be patched, delete num pathname
components from the beginning of each pathname. If the
pathname in the patch file is absolute, any leading
<slash> characters shall be considered the first
component (that is, -p 1
shall remove the leading
<slash> characters). Specifying -p 0
shall cause the
full pathname to be used. If -p
is not specified, only
the basename (the final pathname component) shall be
used.
-R
Reverse the sense of the patch script; that is, assume
that the difference script was created from the new
version to the old version. The -R
option cannot be
used with ed scripts. The patch utility shall attempt
to reverse each portion of the script before applying
it. Rejected differences shall be saved in swapped
format. If this option is not specified, and until a
portion of the patch file is successfully applied,
patch attempts to apply each portion in its reversed
sense as well as in its normal sense. If the attempt is
successful, the user shall be prompted to determine
whether the -R
option should be set.
-r
rejectfile
Override the default reject filename. In the default
case, the reject file shall have the same name as the
output file, with the suffix .rej
appended to it; see
Patch Application.
-u
Interpret the patch file as a unified context
difference (the output of the diff utility when the -u
or -U
options are specified).