Patching Files in Linux / Unix

This post applies to any Linux, Unix, or Mac-terminal users.

A patch file is one of the best methods to do what you think it would do—patch things. This short guide will teach you how to create patch files, and apply them to your files.

Creating Patch Files

Creating patch files requires two things—the original file and the new modified file you have created, that you would like to create a patch for. Run this command respectively:
diff -Naur <original file> <modified file> >> my_patch.patch
Of course, you can change the patch-file’s filename to whatever you would like. Here’s an example of creating a patch:
diff -Naur original.txt modified.txt >> modified.patch

Applying Patch Files

Now we can use this newly-created patch file to patch this same file so it is updated on other people’s systems. To patch a file, run this command, replacing with correct values:
patch -u <original file> <patch file>
For example, let’s patch another original.txt on another system using the patch file we created earlier:
patch -u original.txt modified.patch

That’s really all there is to patching!


19 Responses to “Patching Files in Linux / Unix”

  1. 1 igor December 18, 2007 at 10:57 am

    Dear “engel”, I’ve found your post comment on changing keyboard layout
    engel Says:
    December 14th, 2007 at 21:27:55

    Nevermind, I found the solution. You can get a list of all the characters by viewing the file:



    I am under Ubuntu 6.06 and have found this file, but don’t understand how to interchange the keys: I’d like to have the same layout under LINUX with the one under Windows. Could you describe your further steps?

  2. 2 igor December 19, 2007 at 2:56 am

    What exactly I’d like to change is to change several keys in russian layout of LINUX: I have two-boot system, Windows/Linux(Ubuntu) and layouts are .
    Windows Linux
    6/: 6 /,
    7/? 7/.
    and the keys that should work with AltGrey do not work at all. One more inconveniency is that when I work in MatLab, it does not see power “^”. probably, I have to put somewhere in Matlab the path to this key (since it works in Linux applications – text editors, etc), but I don’t know in which file this key is stored in Linux (again, under Windows this key in MatLab works). Thanks!

  3. 3 igor December 20, 2007 at 12:27 pm

    Thanks a lot, Engel. I have successfuly redefined the main keys that I wanted. Still I do not understand how to define within the russian layout the keys combined with . Is it sufficient to write third column of the definitions in this file ? If YES, then it it important to follow certain formatting? I mean, the relative (or absolute) positions of the coding notations? At last, some of these language files have FOUR columns. Third works with , but which of keys is responsible for the fourth coulumn ( and do not work ).
    Sincerely, Igor

  4. 4 Aichaa July 1, 2012 at 7:02 am

    Hi engel,
    I am trying to make my kernel. During the process, it gives the error:
    ‘patch’ command not found. please install and rebuild. Error 255.

    i am unable to figure out how to install this command??
    Can you please give me some guiding steps through this?

  5. 5 Randy October 15, 2012 at 2:31 pm

    Hi, Nice post thanks for sharing. Would you please consider adding a link to my website on your page. Please email me back.



  6. 6 Adnan November 28, 2012 at 6:29 am

    I need to Patch library in Ubuntu, but i do not really know how to do this.
    Any idea??


  7. 7 Adnan November 28, 2012 at 6:29 am

    I need to Patch library in Ubuntu, but i do not really know how to do this.
    Any idea??


  8. 8 burger king discounts May 11, 2013 at 2:10 pm

    Read on for little ways to save money, and see how
    your efforts can really add up over time. Printable Oakley
    coupons for example can be used to buy a particular item in the actual store.
    Cream Cheese Wontons.

  9. 9 Lee August 13, 2013 at 9:17 am

    I really wish to book mark this specific post, “Patching Files in Linux / Unix |
    Obsessed with the Press” on my own web-site. Would you mind if Ido?
    Many thanks ,Mariam

  10. 10 seopressor wordpress plugin June 10, 2014 at 10:13 pm

    I feel that is among the so much important info for me.
    And i am happy studying your article. However want
    to commentary on few general things, The website taste is perfect, the articles is really nice
    : D. Just right activity, cheers

  11. 11 EndOfLeaseCleanCanberra August 4, 2014 at 1:58 am

    For most up-to-date information you have to visit web and on world-wide-web I
    found this site as a best web page for most recent

  12. 12 adobe photoshop cs6 portable, August 21, 2014 at 8:04 am

    My family members all the time say that I am killing my
    time here at web, but I know I am getting experience every day by reading thes
    good articles.

  13. 13 web site August 29, 2014 at 9:27 pm

    I’m amazed, I have to admit. Rarely do I come
    across a blog that’s both educative and amusing, and
    without a doubt, you’ve hit the nail on the head. The problem is something that not enough people are
    speaking intelligently about. I am very happy that I came across this during my hunt for something concerning this.

  14. 14 mortgage broker December 18, 2014 at 7:21 pm

    My relatives every time say that I am killing my time here at net, however I know I am getting know-how
    all the time by reading thes pleasant posts.

  15. 15 アクポレス October 17, 2016 at 9:30 am

    An outstanding share! I’ve just forwarded this onto a co-worker who was conducting a little research on this.
    And he actually ordered me breakfast because I found it for him…
    lol. So allow me to reword this…. Thank YOU for the meal!!

    But yeah, thanks for spending some time to talk about this issue here on your website.

  16. 16 Max B. December 5, 2016 at 8:45 pm

    I?m impressed, I have to admit. Seldom do I come across a blog that?s equally educative and engaging,
    and without a doubt, you’ve hit the nail on the head.
    The problem is something not enough men and women are speaking intelligently about.
    I’m very happy that I stumbled across this during my search for something relating to this.

  17. 17 eyeoncomputers December 18, 2016 at 7:36 pm

    That’s a nifty way to handle it. A good way to handle this issue in every day practice. Well done! =)

  1. 1 Bookmarks for Monday, December 31st — Trevor Fitzgerald Trackback on December 31, 2007 at 5:33 pm
  2. 2 Yama yapmak çocuk oyuncağıymış! « Akrep55tr Trackback on May 19, 2010 at 10:29 am

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Welcome to the blog of a WordPress developer, documenter, tester, and plugin-writer. Find all things WordPress here, and more.

Dagrio D'Ampessi

%d bloggers like this: