最新消息:20190717 VPS服务器:Vultr新加坡,WordPress主题:大前端D8,统一介绍入口:关于

patch的用法【整理】

工作和技术 crifan 618浏览 0评论

【转】patch的用法

有的时候大家收到的别人移植好的UBOOT了UCLINUC了是以patch包发布的

这里转个写的比较好的patch命令的使用方法

文件:isp1161-2.6.12.patch(在/root下)

— linux-2.6.12/drivers/usb/Makefile 2005-06-17 22:48:29.000000000 +0300
+++ linux-2.6.12-new/drivers/usb/Makefile 2005-07-27 08:11:47.908336540 +0300

……
……

由于patch文件的首行已经指明了路径,所以根据当前所在的目录,加不同的参数使用patch命令:

1:如果当前的目录是和linux-2.6.12的同级目录:

[root@kcn-110mw]#patch -p0 </root/isp1161-2.6.12.patch

2:如果当前的目录为 linux-2.6.12/:

[root@kcn-110mw]#patch -p1 </root/isp1161-2.6.12.patch

3:如果当前的目录为 linux-2.6.12/drivers/:

[root@kcn-110mw]#patch -p2 </root/isp1161-2.6.12.pathc

0,1,2,(或3,4等更多)是指略去的patch文件中的前几级目录

-p 只使用最后的文件名,如上面例子中的Makefile ,而没有任何路径了

patch Command

Purpose

Applies changes to files.

Syntax

patch [ -b [ -B Prefix ] ] [ -f ] [ -l ] [ -N ] [ -R ] [ -s ] [ -v ] [ -c | -e | -n ] [ -d Directory ] [ -D Define ] [ -F Number ] [ -i PatchFile ] [ -o OutFile ] [ -p Number ] [ -r RejectFile ] [ -x Number ] [ File ]

Description

The patch command reads a source file’s instructions on how to change a file, then applies the changes. The source file contains difference listings (or diff listings) produced by the diff command. The diff listings are the result of comparing two files and building instructions about how to reconcile the differences. By default, the patch command uses the source file read from standard input, but this can be overridden using the -i flag and the PatchFile variable.

Diff listings come in three formats: normal, context, or in the style of the ed editor. The patch command determines the diff listing format, unless overruled by the -c, -e, or -n flags.

By default, the patched version of a file replaces the original version. When the -b flag is specified, the original of each patched file is saved in a file of the same name with the suffix .orig appended to it. You may also specify where you want the output to go with the -o flag.

The -p flag makes it possible to customize a patch file to local user directory structures without manually editing the patch file. This is done by specifying how many components to remove from the full path name. For example, if the patch file contained the path name /curds/whey/src/blurfl/blurfl.c, then:

  • -p 0 causes the entire path name to be used.
  • -p 1 removes the leading slash, leaving curds/whey/src/blurfl/blurfl.c.
  • -p 4 removes leading slashes and the first three directories, leaving blurfl/blurfl.c.

Not specifying the -p flag causes the patch command to use the base name. In the above example, that would be blurfl.c.

more detail can refer:

patch Command

转载请注明:在路上 » patch的用法【整理】

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
53 queries in 0.083 seconds, using 18.83MB memory