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!

4 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:

    /usr/include/X11/keysymdef.h

    in http://blog.dotkam.com/2007/06/25/custom-keyboard-layout-in-ubuntu-or-just-linux/

    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

  1. 1 Bookmarks for Monday, December 31st — Trevor Fitzgerald Trackback on December 31, 2007 at 5:33 pm

Leave a Reply