NAME patch - Apply patches to files SYNOPSIS patch [-c | -e | -n | -u] [-d dir] [-D define] [-o outfile] [-p num] [-r rejectfile] [-bflNRU] (-i patchfile | < patchfile) [file] DESCRIPTION patch applies patches to files from difference listings produced by diff(1). patch will skip any garbage unless the patchfile consists entirely of garbage. Garbage is any data that does not conform to the supported difference listing formats. patch supports all difference listing formats specified in diff(1p) except for the -f flag in diff(1p). patch shall figure out which files to patch from the mentions of filenames in the patch, unless the files are specified explicitly. As an extension to the standard, this implementation of patch can determine the filename by looking at the diff-lines that are produced by diff(1) when comparing directories. However, if the file is specified, all patches in the patchfile shall be applied to that file. OPTIONS -b Back up files before the first time that a patch is applied to them. The backups will have the suffix .orig. -c Treat anything that is not conforming to the copied context format as garbage. -d dir Prepend dir to all filenames that appear in the patchfile. -D define Mark added lines with the C preprocessor construct #ifdef define ... #endif Mark removed lines with the C preprocessor construct #ifndef define ... #endif Mark changed lines with the C preprocessor construct #ifdef define ... #else ... #endif As an extension to the standard, define can be 1 or 0 to use #if 1 #if 0 (swap those lines if define is 0) instead of #ifdef define #ifndef define As another extension to the standard, if define begins with an exclamation point (!), #ifdef define #if 1 and #ifndef define #if 0 are swapped. patch does not guarantee that a patched C source code file will be at least as syntactically correct after patching as it was before, despite this being implied by the standard. The syntactic correctness can be broken when edits are made on lines split using line continuation, made in comments, or spanning CPP conditional directives. -e Treat anything that is not conforming to the ed-script format as garbage. -f Don't ask any questions. -i patchfile Read the patchfile instead of standard output. -l Any sequence of whitespace of at least length 1 in the input file shall match any sequence of whitespace of at least length 1 in the difference script when testing if lines match. Additionally, any whitespace at the beginning of a line or at the end of a line is ignored when matching lines. The former case is an extension of the standard. -n Treat anything that is not conforming to the normal format as garbage. -N Ignore already applied hunks. POSIX specifies that already applied patches shall be ignored if this flag is used. A hunk is a contiguous portion of a patch. A patch is a single file-comparison output from diff(1). -o outfile Store resulting files from patches to outfile instead of to the patched file itself. If the patchfile patches multiple files, the results are concatenated. If a patchfile patches a file multiple times, intermediary results are also stored. As an extension to the standard, you may use non-regular files such as /dev/stdout and /dev/null. /dev/null can be used to perform a dryrun. -p num Remove the first num components from filenames that appear in the patchfile. Any leading / is regarded as the first component. If num is 0, the entire filename is used. Without this flag only basename is used. -r rejectfile Save rejected hunks to rejectfile rather than to the filename.rej where filename is the filename of the file that is being patched. Rejected hunks are hunks that cannot be applied. Unless -U is used, rejected hunks are stored in copied context format. However, the timestamps will be omitted. -R Try to apply patches reversed before trying to apply them in normal direction. -u Treat anything that is not conforming to the unified context format as garbage. -U Store rejected hunks in unified context rather than copied context. Copied context is the default even for unified context patches. NOTES Files that become empty as a result of a patch are not removed. Symbolic links are treated as regular files, provided that they link to regular files. Timestamps that appear in diff headers are not applied. Encapsulated patches, and patches with CRLF line breaks — or any other string — rather than LF line breaks are not supported. In this implementation, when the user is prompted, the message is printed to /dev/tty, rather than /dev/stdout despite POSIX's mandate. This is to make it possible to use /dev/stdout as the output file. Unportable characters in filenames are supported by parsing them as C string literals. In this implementation, the -D flag can be used with ed-scripts. SEE ALSO diff(1), ed(1) STANDARDS The patch utility is compliant with the specification except for the exceptions noted above. The [-fU] flags are extensions to that specification, other extensions are noted above.
