About Me

My photo
Working as Technical Lead in CollabNET software private limited.

Tuesday 19 February, 2008

Diff and Patch

I Recently came across two more useful linux commands diff and patch. :)

DIFF:
Display the differences between two files, or each corresponding file in two directories.
SYNTAX
diff [options] from-file to-file > path-file-name

PATCH
SYNTAX
patch -p0 < new-patch
patch -p1 < new-patch
Levels in the Patch Command (-p0 or -p1?):
The -p option will optionally strip off directory levels from the patchfile. For Ex: if you have a patchfile with a header as such:

--- old/modules/pcitable Mon Sep 27 11:03:56 1999
+++ new/modules/pcitable Tue Dec 19 20:05:41 2000

Using a -p0 will expect, from your current working directory, to find a subdirectory called "new", then "modules" below that, then the "pcitable" file below that.

Using a -p1 will strip off the 1st level from the path and will expect to find (from your current working directory) a directory called "modules", then a file called "pcitable". Patch will ignore the "new" directory mentioned in the header of the patchfile.

For more Info:
man diff/patch

No comments: