Diff, Patch, and Friends

“Kernel patches” may sound like magic, but the two tools used to create and apply patches are simple and easy to use—if they weren't, some Linux developers would be too lazy to use them...


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

The first comment asked for

Anonymous's picture

The first comment asked for reasons. Here are a few.

1. Years of fighting with graphical tools can lead one to learn command line tools.

2. A major difference between the two is the former can be used in scripts.

3. Another significant difference is robustness. It's generally much easier to crash a graphical tool than a well-designed command line one.

4. Lastly, command line tools most often contain less code and require less system resources to operate, often making them better suited to work faster and more efficiently than graphical tools.

Smaller, faster and more reliable. Built for automation. A higher learning curve may be a trade off for higher performance.


Jonathan Allen's picture

Why in the world would I want to fight with command line tools when trying to compare and merge versions? Graphical diff and merge tools have existed for decades.

Now if you can show me a diff and merge tool that understands the syntax of the file being compared and I'll be far more interested. I have seen merge tools eat a brace way too often.

I think the images for figure

Anonymous's picture

I think the images for figures 1 and 2 are broken. When I follow the links to view these figures, the images don't show up in my browser window.

using diff and patch

John's picture

If I use diff -Naur to generate a patch symbolic links are not respected. e.g. see below;

How can I get patch/diff to respect symbolic links?

$ ll foo*
total 4
lrwxrwxrwx 1 foo users 5 Jun 9 13:04 link -> stuff
-rw-r--r-- 1 foo users 12 Jun 9 13:04 stuff

total 4
lrwxrwxrwx 1 foo users 5 Jun 9 13:04 link -> stuff
-rw-r--r-- 1 foo users 12 Jun 9 13:04 stuff

$ diff -Naur foo foo2 > patch
$ mv foo2 foo2.orig
$ patch -p0 < patch
patching file foo/link
patching file foo/stuff

$ ll foo
total 8
-rw-r--r-- 1 foo users 27 Jun 9 13:08 link
-rw-r--r-- 1 foo users 27 Jun 9 13:08 stuff


Working with directories

Anonymous's picture

This article is missing info on patching multiple files.

See here: http://lists.gnu.org/archive/html/help-gnu-utils/2004-06/msg00024.html for examlpe.

Re: Diff, Patch, and Friends

Anonymous's picture

Nice article! I now link to it from
my "Howto contribute to an open source project" tutorial,

Re: Diff, Patch, and Friends

Anonymous's picture

You may want to link to the manpages for the free versions
of diff and patch too, instead of only the GNU versions:


To the editor: ed(1) is by no means obsolete; I'm actually
faster with ed than with vi (whose modus operandi is
cruelly to a wordstar-compatible editor user like me).


You didn't mention diff3 either, did you?

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState