patch: Generalized Updating of Files that Differ

patch Like all of Larry Wall's widely used programs (including perl (), a software configuration script called Configure, and the rn news reader), patch betrays a whimsical intelligence of its own. Feed it any kind of diff listing () (not just an editing script produced with the -e option ()). patch figures out what it needs to do to apply the diff, and updates the file, supplying all the while a breezy commentary on what it's doing:


% patch < testfile.diff Hmm... Looks like a normal diff to me... File to patch: testfile Patching file testfile using Plan A... Hunk #1 succeeded at 2. done

As Larry once noted, patch has done an awful lot to "change the culture of computing." Almost all free software is now updated by means of patches rather than complete new releases. patch is smart enough to discard any leading or trailing garbage (such as mail headers or signatures) so that a program source file can be updated by piping a mail message containing a diff listing between old and new versions directly to patch.

Here are a few of the other things patch is smart enough to do:

If you are a developer, patch is worth studying just to see how much a program can do to anticipate errors, deal with fuzzy input, and in general "make the computer do the dirty work." But if you're a developer, you doubtless already know about patch....

One last note: patch is so useful that it's been added to many UNIX systems. Check to see if your system has it before installing it from the tutorial. [I've seen buggy or crippled versions from software vendors, though. The one on the disc is worth comparing to yours. –JP]

- TOR