apply changes to a file
patch applies changes in the style of
to a file. The file to be patched may be specified on the
command line or within the list of changes in a patch
file. By default, patch reads the changes to be made
from the standard input.
patch attempts to determine the type of diff
listing (normal, context, or ed-style). You can overrule
this behavior using the -c, -e, or -n
patch tries to apply several patches in one patch file as
though they come from different patch files; patch must be
able to find out the name of the patch file from each diff
patch accepts the following options:
Saves a (backup) copy of the original contents of each modified file
in a file with the same name as the original plus the suffix
.orig. If multiple patches are applied to the same file,
the backup file is written for the first patch only. patch
creates a backup file out.orig if an output file
out that already exists is also specified using the
Interprets a patch as a context diff (the output from
when the -c or -C option is specified).
Changes directory to dir before processing.
Marks changes within the C conditional compilation construct:
Interprets a patch as an
Reads patch information from the file patch rather than
from the standard input.
Matches any sequence of whitespace characters in the diff
file with any sequence in the input file.
Interprets the patch as normal diff output.
Ignores patches where the differences have already been applied; the
default behavior is to reject such patches.
Directs the output from each applied patch to the file
out. Multiple patches are concatenated within the
file. Does not modify the output file specified on the
command line or in the patch file.
Deletes n leading components from the names of all files
to be patched (leading slashes are counted as one component;
subsequent slashes are not). For example, -p 1 removes the
leading / from absolute pathnames. -p 0 implies
the full pathname is to be used. The default is to use the basename
(the final pathname) component only.
Defines a new name for the reject file (see the
Reverses the sense of the patch script; this may be used in cases
when a diff script was created that shows the changes to
generate an older version of a file from a newer
version. patch attempts to reverse the sense of each
portion of the script before using it. Those differences that it
rejects are saved in swapped format in the reject file; this file
has the same name as each output file with the suffix
If this option is not specified, patch first tries to
apply the script in both the reverse and normal sense. If the normal
sense succeeds, only this sense is applied subsequently. If it
fails, and the reverse sense succeeds, patch prompts you
to ask if you wish it to continue applying changes in the reverse
This option does not work with ed style patch scripts.
patch returns the following values:
One or more lines were written to a reject file.
An error occurred.
The usual way to invoke patch is to redirect the standard
input of patch to read a patch file:
patch < patchfile
The -p option allows you to customize a patch to your
local directory structure without editing the patch file. If the
pathname in the patch file plaster is
/usr/local/example/file.c and you wished to patch
file.c in the current directory:
patch -p 4 < plaster
or more simply:
patch < plaster
To patch /u/local/example/file.c:
patch -p 2 < plaster
The -R option cannot be used with ed scripts
since they do not contain enough information to perform the reverse
The -b option may cause the patched file to be overwritten
for filesystems where the maximum filename length is not long enough
to append the .orig suffix.
Copyright © 1986 Larry Wall.
All rights reserved.
THE SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
patch is conformant with:
ISO/IEC DIS 99452:1992, Information technology Portable Operating System Interface (POSIX) Part 2: Shell and Utilities (IEEE Std 1003.21992);
X/Open CAE Specification, Commands and Utilities, Issue 4, 1992.
© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003