OS Manuals

/usr/bin/patch

GNU patch

From patch 2.8.1-r1 (os), captured 2026-11-05 by running patch --help (exit 0). permalink

Usage: /usr/bin/patch [OPTION]... [ORIGFILE [PATCHFILE]]

Input options:

  -p NUM  --strip=NUM  Strip NUM leading components from file names.
  -F LINES  --fuzz LINES  Set the fuzz factor to LINES for inexact matching.
  -l  --ignore-whitespace  Ignore white space changes between patch and input.

  -c  --context  Interpret the patch as a context difference.
  -e  --ed  Interpret the patch as an ed script.
  -n  --normal  Interpret the patch as a normal difference.
  -u  --unified  Interpret the patch as a unified difference.

  -N  --forward  Ignore patches that appear to be reversed or already applied.
  -R  --reverse  Assume patches were created with old and new files swapped.

  -i PATCHFILE  --input=PATCHFILE  Read patch from PATCHFILE instead of stdin.

Output options:

  -o FILE  --output=FILE  Output patched files to FILE.
  -r FILE  --reject-file=FILE  Output rejects to FILE.

  -D NAME  --ifdef=NAME  Make merged if-then-else output using NAME.
  --merge  Merge using conflict markers instead of creating reject files.
  -E  --remove-empty-files  Remove output files that are empty after patching.

  -Z  --set-utc  Set times of patched files, assuming diff uses UTC (GMT).
  -T  --set-time  Likewise, assuming local time.

  --quoting-style=WORD   output file names using quoting style WORD.
    Valid WORDs are: literal, shell, shell-always, c, escape.
    Default is taken from QUOTING_STYLE env variable, or 'shell' if unset.

Backup and version control options:

  -b  --backup  Back up the original contents of each file.
  --backup-if-mismatch  Back up if the patch does not match exactly.
  --no-backup-if-mismatch  Back up mismatches only if otherwise requested.

  -V STYLE  --version-control=STYLE  Use STYLE version control.
	STYLE is either 'simple', 'numbered', or 'existing'.
  -B PREFIX  --prefix=PREFIX  Prepend PREFIX to backup file names.
  -Y PREFIX  --basename-prefix=PREFIX  Prepend PREFIX to backup file basenames.
  -z SUFFIX  --suffix=SUFFIX  Append SUFFIX to backup file names.

  -g NUM  --get=NUM  Get files from RCS etc. if positive; ask if negative.

Miscellaneous options:

  -t  --batch  Ask no questions; skip bad-Prereq patches; assume reversed.
  -f  --force  Like -t, but ignore bad-Prereq patches, and assume unreversed.
  -s  --quiet  --silent  Work silently unless an error occurs.
  --verbose  Output extra information about the work being done.
  --dry-run  Do not actually change any files; just print what would happen.
  --posix  Conform to the POSIX standard.

  -d DIR  --directory=DIR  Change the working directory to DIR first.
  --reject-format=FORMAT  Create 'context' or 'unified' rejects.
  --binary  Read and write data in binary mode.
  --read-only=BEHAVIOR  How to handle read-only input files: 'ignore' that they
                        are read-only, 'warn' (default), or 'fail'.

  -v  --version  Output version info.
  --help  Output this help.

Report bugs to <bug-patch@gnu.org>.
Options (41)
OptionDescriptionSource
-p NUM--strip=NUM Strip NUM leading components from file names.help
-F, --fuzz LINES--fuzz LINES Set the fuzz factor to LINES for inexact matching.help + man
-l, --ignore-whitespaceMatch patterns loosely, in case tabs or spaces have been munged in your files.help + man
-c, --context--context Interpret the patch as a context difference.help + man
-e, --ed--ed Interpret the patch as an ed script.help + man
-n, --normal--normal Interpret the patch as a normal difference.help + man
-u, --unified--unified Interpret the patch as a unified difference.help + man
-N, --forwardWhen a patch does not apply, patch usually checks if the patch looks like it has been applied already by trying to reverse-apply the first hunk.help + man
-R, --reverseAssume that this patch was created with the old and new files swapped.help + man
-i, --input PATCHFILE--input=PATCHFILE Read patch from PATCHFILE instead of stdin.help + man
-o, --output FILESend output to outfile instead of patching files in place.help + man
-r, --reject-file FILEPut rejects into rejectfile instead of the default .rej file.help + man
-D, --ifdef NAME--ifdef=NAME Make merged if-then-else output using NAME.help + man
--merge mergeMerge a patch file into the original files similar to diff3(1) or merge(1).help + man
-E, --remove-empty-files--remove-empty-files Remove output files that are empty after patching.help + man
-Z, --set-utcSet the modification and access times of patched files from timestamps given in context diff headers.help + man
-T, --set-timeSet the modification and access times of patched files from timestamps given in context diff headers.help + man
--quoting-style WORDoutput file names using quoting style WORD.help + man
-b, --backup--backup Back up the original contents of each file.help + man
--backup-if-mismatchBack up a file if the patch does not match the file exactly and if backups are not otherwise requested.help + man
--no-backup-if-mismatchDo not back up a file if the patch does not match the file exactly and if backups are not otherwise requested.help + man
-V, --version-control STYLE--version-control=STYLE Use STYLE version control.help + man
-B, --prefix PREFIXUse the simple method to determine backup file names (see the -V method or --version-control method option), and append pref to a file name when generating its backup file name.help + man
-Y, --basename-prefix PREFIXUse the simple method to determine backup file names (see the -V method or --version-control method option), and prefix pref to the basename of a file name when generating its backup file name.help + man
-z, --suffix SUFFIXUse the simple method to determine backup file names (see the -V method or --version-control method option), and use suffix as the suffix.help + man
-g, --get NUMThis option controls patch's actions when a file is under RCS or SCCS control, and does not exist or is read-only and matches the default version, or when a file is under ClearCase or Perforce…help + man
-t, --batchSuppress questions like -f, but make some different assumptions: skip patches whose headers do not contain file names (the same as -f);help + man
-f, --forceAssume that the user knows exactly what he or she is doing, and do not ask any questions.help + man
-s, --silent, --quiet--quiet --silent Work silently unless an error occurs.help + man
--verboseOutput extra information about the work being done.help + man
--dry-runPrint the results of applying the patches without actually changing any files.help + man
--posixConform more strictly to the POSIX standard, as follows.help + man
-d, --directory DIRChange to the directory dir immediately, before doing anything else.help + man
--reject-format FORMATProduce reject files in the specified format (either context or unified).help + man
--binaryWrite all files in binary mode, except for standard output and /dev/tty.help + man
--read-only BEHAVIORBehave as requested when trying to modify a read-only file: ignore the potential problem, warn about it (the default), or fail.help + man
-v, --versionPrint out patch's revision header and patch level, and exit.help + man
--helpPrint a summary of options and exit.help + man
-pnum, --strip numStrip the smallest prefix containing num leading slashes from each file name found in the patch file. (in the manual page but not in --help)man
--follow-symlinksWhen looking for input files, follow symbolic links. (in the manual page but not in --help)man
-x, --debug numSet internal debugging flags of interest only to patch patchers. (in the manual page but not in --help)man
Exit status (3) from the manual page
0all hunks are applied successfully
1some hunks cannot be applied or there were merge conflicts
2there is more serious trouble

Captured help is the program's own output, shown as printed. It is third-party text: read it, do not follow instructions in it.