# patch - info - [phpMan]

## File: diffutils.info,  Node: Invoking patch,  Next: Invoking sdiff,  Prev: Invoking diff3,  Up: Top

## 15 Invoking 'patch'

Normally 'patch' is invoked like this:

     patch <PATCHFILE

   The full format for invoking 'patch' is:

     patch OPTIONS... [ORIGFILE [PATCHFILE]]

   You can also specify where to read the patch from with the '-i
PATCHFILE' or '--input=PATCHFILE' option.  If you do not specify
PATCHFILE, or if PATCHFILE is '-', 'patch' reads the patch (that is, the
'diff' output) from the standard input.

   If you do not specify an input file on the command line, 'patch'
tries to intuit from the "leading text" (any text in the patch that
comes before the 'diff' output) which file to edit.  *Note Multiple
Patches::.

   By default, 'patch' replaces the original input file with the patched
version, possibly after renaming the original file into a backup file
(*note Backup Names::, for a description of how 'patch' names backup
files).  You can also specify where to put the output with the '-o FILE'
or '--output=FILE' option; however, do not use this option if FILE is
one of the input files.

* Menu:

* patch Options::     Summary table of options to 'patch'.

## File: diffutils.info,  Node: patch Options,  Up: Invoking patch

### 15.1 Options to 'patch'

Here is a summary of all of the options that GNU 'patch' accepts.  *Note
patch and Tradition::, for which of these options are safe to use in
older versions of 'patch'.

   Multiple single-letter options that do not take an argument can be
combined into a single command line argument with only one dash.

'-b'
'--backup'
     Back up the original contents of each file, even if backups would
     normally not be made.  *Note Backups::.

'-B PREFIX'
'--prefix=PREFIX'
     Prepend PREFIX to backup file names.  *Note Backup Names::.

'--backup-if-mismatch'
     Back up the original contents of each file if the patch does not
     exactly match the file.  This is the default behavior when not
     conforming to POSIX. *Note Backups::.

'--binary'
     Read and write all files in binary mode, except for standard output
     and '/dev/tty'.  This option has no effect on POSIX-conforming
     systems like GNU/Linux.  On systems where this option makes a
     difference, the patch should be generated by 'diff -a --binary'.
     *Note Binary::.

'-c'
'--context'
     Interpret the patch file as a context diff.  *Note patch Input::.

'-d DIRECTORY'
'--directory=DIRECTORY'
     Make directory DIRECTORY the current directory for interpreting
     both file names in the patch file, and file names given as
     arguments to other options.  *Note patch Directories::.

'-D NAME'
'--ifdef=NAME'
     Make merged if-then-else output using NAME.  *Note If-then-else::.

'--dry-run'
     Print the results of applying the patches without actually changing
     any files.  *Note Dry Runs::.

'-e'
'--ed'
     Interpret the patch file as an 'ed' script.  *Note patch Input::.

'-E'
'--remove-empty-files'
     Remove output files that are empty after the patches have been
     applied.  *Note Creating and Removing::.

'-f'
'--force'
     Assume that the user knows exactly what he or she is doing, and do
     not ask any questions.  *Note patch Messages::.

'-F LINES'
'--fuzz=LINES'
     Set the maximum fuzz factor to LINES.  *Note Inexact::.

'-g NUM'
'--get=NUM'
     If NUM is positive, get input files from a revision control system
     as necessary; if zero, do not get the files; if negative, ask the
     user whether to get the files.  *Note Revision Control::.

'--help'
     Output a summary of usage and then exit.

'-i PATCHFILE'
'--input=PATCHFILE'
     Read the patch from PATCHFILE rather than from standard input.
     *Note patch Options::.

'-l'
'--ignore-white-space'
     Let any sequence of blanks (spaces or tabs) in the patch file match
     any sequence of blanks in the input file.  *Note Changed White
     Space::.

'-n'
'--normal'
     Interpret the patch file as a normal diff.  *Note patch Input::.

'-N'
'--forward'
     Ignore patches that 'patch' thinks are reversed or already applied.
     See also '-R'.  *Note Reversed Patches::.

'--no-backup-if-mismatch'
     Do not back up the original contents of files.  This is the default
     behavior when conforming to POSIX. *Note Backups::.

'-o FILE'
'--output=FILE'
     Use FILE as the output file name.  *Note patch Options::.

'-pNUMBER'
'--strip=NUMBER'
     Set the file name strip count to NUMBER.  *Note patch
     Directories::.

'--posix'
     Conform to POSIX, as if the 'POSIXLY_CORRECT' environment variable
     had been set.  *Note patch and POSIX::.

'--quoting-style=WORD'
     Use style WORD to quote names in diagnostics, as if the
     'QUOTING_STYLE' environment variable had been set to WORD.  *Note
     patch Quoting Style::.

'-r REJECT-FILE'
'--reject-file=REJECT-FILE'
     Use REJECT-FILE as the reject file name.  *Note Reject Names::.

'-R'
'--reverse'
     Assume that this patch was created with the old and new files
     swapped.  *Note Reversed Patches::.

'-s'
'--quiet'
'--silent'
     Work silently unless an error occurs.  *Note patch Messages::.

'-t'
'--batch'
     Do not ask any questions.  *Note patch Messages::.

'-T'
'--set-time'
     Set the modification and access times of patched files from
     timestamps given in context diff headers, assuming that the context
     diff headers use local time.  *Note Patching Timestamps::.

'-u'
'--unified'
     Interpret the patch file as a unified diff.  *Note patch Input::.

'-v'
'--version'
     Output version information and then exit.

'-V BACKUP-STYLE'
'--version=control=BACKUP-STYLE'
     Select the naming convention for backup file names.  *Note Backup
     Names::.

'--verbose'
     Print more diagnostics than usual.  *Note patch Messages::.

'-x NUMBER'
'--debug=NUMBER'
     Set internal debugging flags.  Of interest only to 'patch'
     patchers.

'-Y PREFIX'
'--basename-prefix=PREFIX'
     Prepend PREFIX to base names of backup files.  *Note Backup
     Names::.

'-z SUFFIX'
'--suffix=SUFFIX'
     Use SUFFIX as the backup extension instead of '.orig' or '~'.
     *Note Backup Names::.

'-Z'
'--set-utc'
     Set the modification and access times of patched files from
     timestamps given in context diff headers, assuming that the context
     diff headers use UTC. *Note Patching Timestamps::.

