# Ed (text editor)

**ed** is a line-oriented text editor for Unix and [Unix-like](https://www.edgepedia.org/unix-like) operating systems, in which the user addresses and modifies the file one line or line range at a time through typed commands rather than through a visible, continuously updated screen. It was the original editor for Unix, written by [Ken Thompson](https://www.edgepedia.org/ken-thompson), and it remains a required utility in the POSIX standard, which is why it still ships with essentially every Unix-like system.<sup>[1](https://www.gnu.org/software/ed/manual/ed_manual.html)</sup><sup> • </sup><sup>[2](https://www.nokia.com/bell-labs/about/dennis-m-ritchie/qed.html)</sup><sup> • </sup><sup>[3](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ed.html)</sup>

| Key fact | Detail |
|---|---|
| Type | Line-oriented text editor, usable interactively and from shell scripts<sup>[1](https://www.gnu.org/software/ed/manual/ed_manual.html)</sup> |
| Origin | First written by Ken Thompson for the PDP-7, derived from the QED editor<sup>[2](https://www.nokia.com/bell-labs/about/dennis-m-ritchie/qed.html)</sup> |
| First shipped | Included in the First Edition Unix (1971), used for text processing of patent documents<sup>[4](https://www.unix.org/unix_history.html)</sup> |
| Command structure | Zero, one, or two line addresses followed by a single-character command and optional parameters<sup>[3](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ed.html)</sup> |
| Regular expressions | POSIX basic regular expressions, matched against single lines only<sup>[3](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ed.html)</sup> |
| Standard status | A required utility in POSIX.1-2017; the only editor guaranteed present on a conforming system<sup>[3](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ed.html)</sup> |
| Current GNU version | GNU ed 1.22.5 (6 February 2026)<sup>[1](https://www.gnu.org/software/ed/manual/ed_manual.html)</sup><sup> • </sup><sup>[5](https://ftp.gnu.org/gnu/ed/)</sup> |

## Origin in QED and early Unix

ed descends from QED, a line editor first written by [Butler Lampson](https://www.edgepedia.org/butler-lampson) and Peter Deutsch for the Berkeley time-sharing system on the SDS 940. Ken Thompson used that QED at Berkeley, and after arriving at [Bell Labs](https://www.edgepedia.org/bell-labs) wrote a new version for the MIT CTSS system in [IBM 7090](https://www.edgepedia.org/ibm-7090) assembly language. That version introduced regular expressions for searching and substitution; until then, editors could search only for literal strings. Thompson compiled each regular expression on the fly into machine code implementing a nondeterministic finite automaton, a technique he published in the *Communications of the ACM* and patented.<sup>[2](https://www.nokia.com/bell-labs/about/dennis-m-ritchie/qed.html)</sup>

When Thompson and [Dennis Ritchie](https://www.edgepedia.org/dennis-ritchie) began building Unix on a little-used PDP-7 at Bell Labs in 1969, ed was among the first programs written for the new system. Thompson allocated a week each to the operating system, the shell, the editor, and the assembler.<sup>[6](https://s3-us-west-2.amazonaws.com/belllabs-microsite-unixhistory/takeshape.html)</sup> The First Edition Unix of 1971, running on the PDP-11/20, included an assembler, a file system, fork(), roff, and ed, and the system was used for text processing of patent documents.<sup>[4](https://www.unix.org/unix_history.html)</sup> The 1974 CACM paper by Ritchie and Thompson likewise lists "text editor based on QED" among the major programs of the system.<sup>[7](https://people.eecs.berkeley.edu/~adj/cs262/papers/unix.pdf)</sup>

In moving from QED to ed, Thompson simplified deliberately. ed kept the line orientation but reduced the regular expressions to a minimal set with no alternation and no parentheses, so that the language could not even express all regular languages; Ritchie judged this "not much of a loss." ed also dropped QED's multiple buffers and buffer execution. Later Unix versions of ed, rewritten in C, gradually restored some complexity such as back-references in regular expressions.<sup>[2](https://www.nokia.com/bell-labs/about/dennis-m-ritchie/qed.html)</sup>

## How the editor works

ed operates on a copy of the file, called the buffer; changes have no effect on the file until a w (write) command is given, and unsaved changes are lost on quitting.<sup>[1](https://www.gnu.org/software/ed/manual/ed_manual.html)</sup> The editor has two modes. In command mode, input characters are interpreted as commands; in input mode, they are collected as text. Input mode ends with a line consisting of a single period followed by a newline.<sup>[8](https://www.man7.org/linux/man-pages/man1/ed.1p.html)</sup>

Commands have a regular structure: zero, one, or two addresses followed by a single-character command and possibly parameters. Addresses select lines in the buffer; the period addresses the current line, the dollar sign addresses the last line, and a decimal number n addresses the nth line. Every command that requires addresses has defaults, so addresses can often be omitted.<sup>[8](https://www.man7.org/linux/man-pages/man1/ed.1p.html)</sup> Commands operate on whole lines or ranges of lines: d deletes lines, m moves them, and even the substitute command s, which can change part of a line, is applied to whole lines at a time.<sup>[1](https://www.gnu.org/software/ed/manual/ed_manual.html)</sup>

ed supports the basic regular expressions mandated by POSIX. Because regular expressions are always matched against single lines, never against larger sections of text, a regular expression cannot match a newline.<sup>[3](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ed.html)</sup> GNU ed offers an -E option to use extended regular expressions instead.<sup>[1](https://www.gnu.org/software/ed/manual/ed_manual.html)</sup>

If ed is interrupted while the buffer contains unsaved changes, or if a terminal disconnect occurs with a SIGHUP, the editor attempts to save the buffer to a file named ed.hup, first in the current directory and then in the home directory.<sup>[8](https://www.man7.org/linux/man-pages/man1/ed.1p.html)</sup>

## Descendants and influence

ed's command language became the vocabulary of Unix text processing.

The line of descent among editors is just as evident. ed gave rise to ex, a somewhat less terse offshoot; from ex came vi, the full-screen visual mode that [Bill Joy](https://www.edgepedia.org/bill-joy) built over ex at Berkeley in 1976. Under the name ex, the same program works on typewriter-like terminals and is essentially ed with fancier commands and better diagnostics.<sup>[10](https://thingshavehistory.com/posts/ed/)</sup><sup> • </sup><sup>[2](https://www.nokia.com/bell-labs/about/dennis-m-ritchie/qed.html)</sup>

ed scripts remain a machine-readable change format. The diff utility's -e option produces a script that, when fed to ed along with an appended w command, converts file1 into file2.<sup>[11](https://www.man7.org/linux/man-pages/man1/diff.1p.html)</sup>

## Implementations and standards

POSIX.1-2017 specifies ed as a line-oriented editor with command and input modes, the -p prompt option, and the -s option that suppresses byte counts written by the e, E, r, and w commands. The standard records historical variations: BSD-based systems did not support the addresses ; and ,, allowed command/suffix pairs such as pp that POSIX leaves unspecified, and lacked the undo of the j, m, r, s, and t commands.<sup>[8](https://www.man7.org/linux/man-pages/man1/ed.1p.html)</sup>

Early versions of the standard documented a limit, {ED_FILE_MAX}, reflecting historical implementations that had problems with files larger than 100000 bytes; that limit was removed, and POSIX now requires implementations to document their file size limits. The separate {ED_LINE_MAX} limit was also removed in favor of the general {LINE_MAX} limit for input and output lines.<sup>[3](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ed.html)</sup> Some implementations, such as z/VM's OpenExtensions, still document their own bounds, for example a limit of 500,000 lines per file.<sup>[12](https://www.ibm.com/docs/en/SSB27U_7.4.0/pdf/dmsp0_v7r4.pdf)</sup>

**GNU ed.** The GNU implementation, maintained by the [Free Software Foundation](https://www.edgepedia.org/free-software-foundation), is documented as version 1.22.5 (6 February 2026) and is based on the editor algorithm in Brian W. Kernighan and P. J. Plauger's book *Software Tools in Pascal* (Addison-Wesley, 1981). It includes a restricted variant, red, which can edit only files in the current directory and cannot execute shell commands. Options include -G for traditional behavior, -r for restricted mode, -p for a prompt string, and -s for script use. Exit statuses are 0 for a normal exit, 1 for environmental problems, 2 for input-file problems, and 3 for an internal consistency error.<sup>[1](https://www.gnu.org/software/ed/manual/ed_manual.html)</sup>

For historical compatibility, ed provides no command-line editing or history; a common workaround is the rlwrap utility, which supplies line editing, history, and completion around the raw editor.<sup>[13](https://github.com/slewsys/ed)</sup>

## Use today

ed's practical role has narrowed, and the GNU manual itself notes that for most purposes it is superseded by full-screen editors.<sup>[1](https://www.gnu.org/software/ed/manual/ed_manual.html)</sup> It retains a niche: its command language remains a live dependency: diff -e output, ed scripts in software distribution, and the ex/ed command mode of vi all assume familiarity with it.<sup>[11](https://www.man7.org/linux/man-pages/man1/diff.1p.html)</sup>

## References

1. [The GNU ed line editor, GNU ed manual (version 1.22.5), Free Software Foundation](https://www.gnu.org/software/ed/manual/ed_manual.html)
2. [Dennis Ritchie, "An incomplete history of the QED Text Editor," Nokia Bell Labs](https://www.nokia.com/bell-labs/about/dennis-m-ritchie/qed.html)
3. [ed, The Open Group Base Specifications Issue 7, 2018 Edition (POSIX.1-2017)](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ed.html)
4. [History of UNIX, The Open Group](https://www.unix.org/unix_history.html)
5. [Index of /gnu/ed, GNU FTP server](https://ftp.gnu.org/gnu/ed/)
6. [The Creation of the UNIX Operating System: The UNIX system begins to take shape, Bell Labs](https://s3-us-west-2.amazonaws.com/belllabs-microsite-unixhistory/takeshape.html)
7. [Dennis M. Ritchie and Ken Thompson, "The UNIX Time-Sharing System," Communications of the ACM (1974)](https://people.eecs.berkeley.edu/~adj/cs262/papers/unix.pdf)
8. [ed(1p), POSIX Programmer's Manual, Linux man-pages project](https://www.man7.org/linux/man-pages/man1/ed.1p.html)
9. [Beginning Unix (2005), Wrox](https://1403.iee.ihu.gr/files_books/03.BEGINNING_UNIX__2005_.PDF)
10. [ed: the editor that still ships with every Unix, Things Have History](https://thingshavehistory.com/posts/ed/)
11. [diff(1p), POSIX Programmer's Manual, Linux man-pages project](https://www.man7.org/linux/man-pages/man1/diff.1p.html)
12. [z/VM 7.4 OpenExtensions POSIX Conformance Document, IBM](https://www.ibm.com/docs/en/SSB27U_7.4.0/pdf/dmsp0_v7r4.pdf)
13. [slewsys/ed: The Unix line editor, GitHub](https://github.com/slewsys/ed)

---
*Topic: Encyclopedia › Technology and the built world › Computing and digital systems › Software and programming › Development tools and collaboration infrastructure › Build, deployment, and development tooling*

*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026; Oct 25, 2026 · Last review: Oct 15, 2026*

*Copyright 2026 EdgeChat AI, a subsidiary of Biostate AI.*

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license
