Skip to content
Main menu
  • Main page
  • Discover
  • Unexpected connections
  • Topics
  • Random article
  • Search
Your library
  • Saved articles
  • Recent discoveries
  • Rabbit-hole trails
Topic areas
  • Computer Science
  • Mathematics
  • Physics
  • Engineering
  • Biology
  • Economics
  • Curiosities
WikiholeDeeper into Wikipedia
EnglishEN
  • Saved
  • History

  • Article text and media come live from Wikipedia via the official MediaWiki API and are available under the Creative Commons Attribution-ShareAlike 4.0 License; additional terms may apply. Each article links to its source and revision.
  • WikiHole is an independent project and is not affiliated with the Wikimedia Foundation.
  • How ranking works
  • All topics
  • Reading history
  • Random article
  • MediaWiki API

patch (Unix)

  • Article
  • Rabbit hole
  • Read
  • View history
Tools
Actions
  • Read
  • View history
General
  • Recent changes
  • Related articles
  • Random discovery
This article
Reading time
3 min
Topic
Computer Science
Quality
Start-class
Released
1984
Views
494 in 14 days
Last edited
20 Sept 2026
Print/export
  • Printable version
In other projects
  • Wikidata item
From Wikipedia, the free encyclopedia
Rabbit hole:
  1. Patch (Unix)
Patch (Unix)
Command for applying changes to text files
Original authorLarry Wall
DevelopersPaul Eggert, Wayne Davison, David MacKenzie, Andreas Grünbacher
ReleaseMay 24, 1985 (1985-05-24)
Operating systemUnix and Unix-like, Plan 9, MSX-DOS, Microsoft Windows
PlatformCross-platform
TypeCommand

patch is a shell command that updates text files according to instructions in a separate file, called a . The file is a text file that lists the differences between the input file and the desired content. The command is designed to support patch files created via . A user creates a patch file by running for two versions of a file (original and target), which produces a list of differences that can later use to generate the target file from the original file plus the patch file. The term is also a verb for applying a patch.

patch file
patch
diff
diff
patch
patch

Developed by a programmer for other programmers, patch was frequently used for updating source code to a newer version. Because of this, many people came to associate patches with source code, whereas patches can in fact be applied to any text. Patched files do not accumulate any unneeded text, which is what some people perceive based on the English meaning of the word; patch is as capable of removing text as it is of adding it.

Patches described here should not be confused with binary patches, which, although they can be conceptually similar, are distributed to update binary files comprising the program to a new release.

The original patch program was written by Larry Wall (who went on to create the Perl programming language) and posted to mod.sources1 (which later became comp.sources.unix) in May 1985. patch was added to XPG4, which later became POSIX.2 Wall's code remains the basis of "patch" programs provided in OpenBSD,3 FreeBSD,4 and schilytools.5 The Open Software Foundation, which merged into The Open Group, is said to have maintained a derived version. The GNU project/FSF maintains its patch, forked from the Larry Wall version. The repository is different from that of GNU diffutils, but the documentation is managed together.6 Originally written for Unix, the command has also been ported to Windows (via GnuWin32 and UnxUtils) and many other platforms. An implementation is part of ASCII's MSX-DOS2 Tools for MSX-DOS version 2.7

Loading the rest of the article…

Recent changes

Rabbit hole

Where Patch (Unix) leads. Every connection below has a source: a link in this article, a shared Wikipedia category, or CirrusSearch text similarity. Articles already on your trail are left out.

Contents
  • (Top)
  • Use
  • Examples
  • See also
  • References
  • External links
  • Recent changes
  • Rabbit hole
Contents
Contents7 sections
  • (Top)
  • Use
  • Advanced diffs
  • Examples
  • See also
  • References
  • External links
  • Recent changes
  • Rabbit hole
Study aids for Patch (Unix)

Terminology

patch file
patch is a shell command that updates text files according to instructions in a separate file, called a patch file.

Terms the article defines in bold, quoted in context.

Categories:
  • 1984 software
  • Patch utilities
  • Plan 9 commands
  • Unix SUS2008 utilities

752 words · 7 references · revision 1375889705 · CC BY-SA 4.0

General
  • Recent changes
  • Related articles
  • Random discovery
This article
Reading time
3 min
Topic
Computer Science
Quality
Start-class
Released
1984
Views
494 in 14 days
Last edited
20 Sept 2026

Key concepts

  • Patch (computing)2
  • Shell (computing)1
  • Command (computing)1
  • Text file1
  • Source code1
  • Computer program1
  • Larry Wall1
  • Perl1
  • Programming language1
  • POSIX1

The articles this one links to most, weighted towards the introduction.

Print/export
  • Printable version
In other projects
  • Wikidata item

Use

As patch files are text, they can be used with processes such as quality review and modification via a text editor.

In addition to the diff command, a patch file can be produced by other programs, such as Subversion, CVS, RCS, Mercurial and Git.

Patches have been the crucial component of many source control systems, including CVS.

Advanced diffs

Further information: diff § Variations

When more advanced diffs are used, patches can be applied even to files that have been modified in the meantime, as long as those modifications do not interfere with the patch. This is achieved by using "context diffs" and "unified diffs" (also known as "unidiffs"), which surround each change with context, which is the text immediately before and after the changed part. Patch can then use this context to locate the region to be patched, even if it has been displaced by changes earlier in the file, using the line numbers in the diffs as a starting point. Because of this property, context and unified diffs are the preferred form of patches for submission to many software projects.

The above features make diff and patch especially popular for exchanging modifications to open-source software. Outsiders can download the latest publicly available source code, make modifications to it, and send them, in diff form, to the development team. Using diffs, the development team has the ability to effectively review the patches before applying them, and can apply them to a newer code base than the one the outside developer had access to.

Examples

The following command creates a patch file, patchFile, that encodes how to generate newFile from oldFile. The -u option selects to output in unified diff format.

$ diff -u oldFile newFile > patchFile

The following command applies the changes to the file identified in patchFile.

$ patch < patchFile

Patching a file in a subdirectory requires the additional -pnumber option, where number is 1 if the base directory of the source tree is included in the diff, and 0 otherwise.

A patch can be undone, or reversed, with the -R option:

$ patch -R < patchFile

If the file used as the original is significantly different from the actual original file, the patch cannot be cleanly applied. For example, if lines of text are inserted at the beginning, the line numbers referred to in the patch will be incorrect. patch is able to recover from this by looking at nearby lines to relocate the text to be patched. It will also recover when lines of context (for context and unified diffs) are altered; this is described as fuzz.

See also

  • Quilt (software)
  • rsync
  • xdelta
  • List of POSIX commands
  • IBM Mainframe utility IEBUPDTE, a mainframe patch program, created about 20 years earlier (circa ~1964).

References

  1. 1Wall, Larry (May 8, 1985). "patch version 1.3". Newsgroup: mod.sources. Archived from the original on 2023-04-04. Retrieved 2024-07-14.
  2. 2patch – Shell and Utilities Reference, The Single UNIX Specification, Version 5 from The Open Group
  3. 3http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/patch/ Archived 2017-06-07 at the Wayback Machine OpenBSD patch source
  4. 4FreeBSD – Shell and Utilities Reference, The Single UNIX Specification, Version 5 from The Open Group
  5. 5"Schilytools". from the original on 2023-05-08. Retrieved 2023-05-08.

External links

  • GNU Diffutils (includes diff and patch); Documentation
  • GNU tools for Win32 – Win32 port of tools, including diff and patch
  • Dickey, Thomas E. "DIFFSTAT – make histogram from diff-output". Archived from the original on 2020-01-22. Retrieved 2020-05-01
Archived
  • 6"Patch.c\SRC - patch.git - GNU patch". Archived from the original on 2023-05-08. Retrieved 2023-05-08.
  • 7MSX-DOS2 Tools User's Manual by ASCII Corporation
  • Created
    19 Feb 2004
    History
    253 edits
    163 contributors
    No edits in the last 30 days
    Last edited
    20 Sept 2026

    253 revisions in total · 163 contributors

    1. 20 Sept 2026, 18:16 UTCBkellcitations needed for claims that people have misconceptions+78diff
    2. 10 May 2026, 18:16 UTCIdiosyncraticLawyermWording, formatting−17diff
    3. 10 May 2026, 18:14 UTCIdiosyncraticLawyermFormatting, punctuation−45diff
    4. 10 May 2026, 17:52 UTCTedickeyrevert - not an improvement (take a look at before/after)+13diff
    5. 10 May 2026, 16:24 UTCIdiosyncraticLawyermrevertedRemoving illicit template parameter−13diff
    6. 29 Mar 2026, 18:31 UTCTedickeyrevert - already linked and discussed in this topic−24diff
    7. 29 Mar 2026, 12:07 UTCMisuteramreverted§ Examples Add link+24diff
    8. 10 Mar 2026, 16:40 UTCMsxC50oCMVZXh4M9mAdded a missing 'the'+4diff

    View full revision history

    Created
    19 Feb 2004
    History
    253 edits
    163 contributors
    No edits in the last 30 days
    Last edited
    20 Sept 2026

    Related articles are unavailable right now.

    Wikipedia is rate limiting us right now. Try again in a minute.