Linux patch command details how to use the Linux patch command

Source: Internet
Author: User
Tags diff local time

The patch command allows you to modify and update the original file by setting the patch file. If only one file is modified at a time, you can issue commands in the command column for sequential execution. If files are patched together, a large number of files can be repaired at a time, which is also one of the core upgrade methods for Linux systems.

Syntax

Patch [-bceEflnNRstTuvZ] [-B <backup character string>] [-d <working Directory>] [-D <symbol>] [-F <>] [-g <control value>] [-I <patch file>] [-o <output file>] [-p <strip level>] [-r <reject File>] [-V <backup mode>] [-Y <backup start string>] [-z <backup end string>] [-- backup-if-mismatch] [-- binary] [-- help] [-- nobackup-if-mismatch] [-- verbose] [original file <patch file>] or path [-p <Peel level>] <[patch file]

Parameters:

  • -B or -- backup backs up each original file.

  • -B <backup character string> or -- prefix = <backup character string> specifies the first character string appended to the file name during file backup. This character string can be a path name.

  • -C or -- context interprets the patch data as a difference in associativity.

  • -D <working directory> or -- directory = <working directory> to set the working directory.

  • -D <symbol> or -- ifdef = <symbol> marks the changed place with the specified symbol.

  • -E or -- ed interprets the patch data as a description file available for the ed command.

  • -E or -- remove-empty-files: if the content of the output file is blank after patching, the file is removed.

  • -F or -- force: the effect of this parameter is similar to that of the specified "-t" parameter, but it is assumed that the version of the patched data is the new version.

  • -F <monitoring columns> or -- fuzz <monitoring columns> sets the maximum number of monitoring columns.

  • -G <control value> or -- get = <control value> is set to RSC or SCCS to control the repair job.

  • -I <patch file> or -- input = <patch file> Read the specified patch.

  • -L or -- ignore-whitespace ignores the skip and space characters between patched data and input data.

  • -N or -- normal interprets the patch data as a general difference.

  • -N or -- forward indicates that the repaired data is older than the original file version, or that the repaired data of this version has been used.

  • -O <output file> or -- output = <output file> sets the name of the output file. Repaired files are stored in this name.

  • -P <strip level> or -- strip = <strip level> specifies the path names of the layers to be stripped.

  • -F <reject file> or -- reject-file = <reject file> sets the name of the file to save the information related to rejection. The default file name is. rej.

  • -R or -- reverse assume that the repaired data is generated by the location where the new and old files are exchanged.

  • -S or -- quiet or -- silent does not display the command execution process unless an error occurs.

  • -T or -- batch automatically skips the error and does not ask any questions.

  • -T or -- set-time: the effect of this parameter is similar to that of the specified "-Z" parameter, but the local time is the main parameter.

  • -U or -- uniied interprets the patch data as a consistent difference.

  • -V or -- version displays version information.

  • -V <backup mode> or -- version-control = <backup mode> use the "-B" parameter to back up the target file. A backup string is added at the end of the backup file, this string can be changed not only by the "-z" parameter, but also by using the "-V" parameter to specify different backup methods.

  • -Y <backup character string> or -- basename-prefix = -- <backup character string>: append the string to the beginning of the basic file name when setting file backup.

  • -Z <backup character string> or -- suffix = <backup character string> this parameter works similarly to the specified "-B" parameter, the difference is that the path and file name used for the repair job are src/linux/fs/super. c. After adding the "backup/" string, the file super. c will be backed up in the/src/linux/fs/backup directory.

  • -Z or -- set-utc change the repaired files and set the access time to UTC.

  • -- Backup-if-mismatch: The file is backed up only when the repaired data is not completely consistent and the file is not specified.

  • -- Binary reads and writes data in binary mode without passing the standard output device.

  • -- Help online help.

  • -- Nobackup-if-mismatch: When the patch data is not completely consistent, and the file is not specified to be backed up, do not back up the file.

  • -- Verbose displays the execution process of commands in detail.

Instance

Use the patch command to upgrade the file "testfile1". The patch file is "testfile. patch". Enter the following command:

$ Patch-p0 testfile1 testfile. patch # use the patch to upgrade the file

Before using this command, you can use the command "cat" to view the content of "testfile1. You can use the command "diff" to compare the file to be updated with the original file to generate a patch file. The procedure is as follows:

$ Cat testfile1 # view the content of testfile1 Hello, This is the firstfile! $ Cat testfile2 # view the content of testfile2 Hello, Thisisthesecondfile! $ Diff testfile1 testfile2 # compare two files: 1c1 <Hello, Thisisthefirstfile! ---> Hello, Thisisthesecondfile! # Save the comparison result to the tetsfile. patch file $ diff testfile1 testfile2> testfile. patch $ cat testfile. patch # view the content of the patch package 1c1 <Hello, Thisisthefirstfile! ---> Hello, Thisisthesecondfile! # Use the patch package to upgrade the testfile1 file $ patch-p0 testfile1 testfile. patch patching file testfile1 $ cat testfile1 # view the content of testfile1 again # the testfile1 file is changed to the same content as testfile2 Hello, This is the secondfile!

Note: in the code above, "$ diff testfile1 testfile2> testfile. patch "the operator used"> "indicates to write the file data on the left of the operator to the file pointed to on the right. Here, it refers to writing the comparison results of the two files to the file "testfile. patch.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.