(pronounced as distinct letters, ) is a
line editor
In computing, a line editor is a text editor in which each editing command applies to one or more complete lines of text designated by the user. Line editors predate screen-based text editors and originated in an era when a computer operator typic ...
for
Unix
Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
and
Unix-like
A Unix-like (sometimes referred to as UN*X, *nix or *NIX) operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Uni ...
operating systems. It was one of the first parts of the Unix operating system that was developed, in August 1969.
It remains part of the
POSIX
The Portable Operating System Interface (POSIX; ) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines application programming interfaces (APIs), along with comm ...
and
Open Group standards for Unix-based operating systems,
alongside the more sophisticated full-screen editor
vi.
History and influence
The ed text editor was one of the first three key elements of the Unix operating system—
assembler,
editor
Editing is the process of selecting and preparing written, visual, audible, or cinematic material used by a person or an entity to convey a message or information. The editing process can involve correction, condensation, organization, a ...
, and
shell
Shell may refer to:
Architecture and design
* Shell (structure), a thin structure
** Concrete shell, a thin shell of concrete, usually with no interior columns or exterior buttresses
Science Biology
* Seashell, a hard outer layer of a marine ani ...
—developed by
Ken Thompson
Kenneth Lane Thompson (born February 4, 1943) is an American pioneer of computer science. Thompson worked at Bell Labs for most of his career where he designed and implemented the original Unix operating system. He also invented the B (programmi ...
in August 1969 on a
PDP-7
The PDP-7 is an 18-bit computing, 18-bit minicomputer produced by Digital Equipment Corporation as part of the Programmed Data Processor, PDP series. Introduced in 1964, shipped since 1965, it was the first to use their Flip-Chip module, Flip- ...
at
AT&T Bell Labs.
Many features of ed came from the
qed text editor developed at Thompson's
alma mater University of California, Berkeley
The University of California, Berkeley (UC Berkeley, Berkeley, Cal, or California), is a Public university, public Land-grant university, land-grant research university in Berkeley, California, United States. Founded in 1868 and named after t ...
. Thompson was very familiar with qed, and had reimplemented it on the
CTSS and
Multics
Multics ("MULTiplexed Information and Computing Service") is an influential early time-sharing operating system based on the concept of a single-level memory.Dennis M. Ritchie, "The Evolution of the Unix Time-sharing System", Communications of t ...
systems. Thompson's versions of qed were notable as the first to implement
regular expression
A regular expression (shortened as regex or regexp), sometimes referred to as rational expression, is a sequence of characters that specifies a match pattern in text. Usually such patterns are used by string-searching algorithms for "find" ...
s. Regular expressions are also implemented in ed, though their implementation is considerably less general than that in qed.
Dennis M. Ritchie produced what
Doug McIlroy later described as the "definitive" ed,
and aspects of ed went on to influence
ex, which in turn spawned
vi. The non-interactive Unix command
grep was inspired by a common special use of qed and later ed, where the command
g/re/p
performs a global regular expression search and prints the lines containing matches. The Unix stream editor,
sed implemented many of the scripting features of
qed that were not supported by ed on Unix.
[
]
Features
Features of ed include:
* available on essentially all Unix systems (and mandatory on systems conforming to the
Single Unix Specification
The Single UNIX Specification (SUS) is a standard for computer operating systems, compliance with which is required to qualify for using the "UNIX" trademark. The standard specifies programming interfaces for the C language, a command-line shell, ...
).
* support for
regular expression
A regular expression (shortened as regex or regexp), sometimes referred to as rational expression, is a sequence of characters that specifies a match pattern in text. Usually such patterns are used by string-searching algorithms for "find" ...
s
* powerful automation can be achieved by feeding commands from
standard input
Known for its terseness, ed, compatible with
teletype
A teleprinter (teletypewriter, teletype or TTY) is an electromechanical device that can be used to send and receive typed messages through various communications channels, in both point-to-point and point-to-multipoint configurations.
Init ...
terminals like
Teletype Model 33, gives almost no visual feedback,
and has been called (by
Peter H. Salus) "the most user-hostile editor ever created", even when compared to the contemporary (and notoriously complex)
TECO. For example, the message that ed will produce in case of error, ''and'' when it wants to make sure the user wishes to quit without saving, is "?". It does not report the current filename or line number, or even display the results of a change to the text, unless requested. Older versions (c. 1981) did not even ask for confirmation when a quit command was issued without the user saving changes.
This terseness was appropriate in the early versions of Unix, when consoles were
teletypes,
modem
The Democratic Movement (, ; MoDem ) is a centre to centre-right political party in France, whose main ideological trends are liberalism and Christian democracy, and that is characterised by a strong pro-Europeanist stance. MoDem was establis ...
s were slow, and
memory
Memory is the faculty of the mind by which data or information is encoded, stored, and retrieved when needed. It is the retention of information over time for the purpose of influencing future action. If past events could not be remembe ...
was precious. As computer technology improved and these constraints were loosened, editors with more visual feedback became the norm.

In current practice, ed is rarely used interactively, but does find use in some
shell script
A shell script is a computer program designed to be run by a Unix shell, a command-line interpreter. The various dialects of shell scripts are considered to be command languages. Typical operations performed by shell scripts include file manipu ...
s. For interactive use, ed was subsumed by the
sam,
vi and
Emacs
Emacs (), originally named EMACS (an acronym for "Editor Macros"), is a family of text editors that are characterized by their extensibility. The manual for the most widely used variant, GNU Emacs, describes it as "the extensible, customizable, s ...
editors in the 1980s. ed can be found on virtually every version of Unix and
Linux
Linux ( ) is a family of open source Unix-like operating systems based on the Linux kernel, an kernel (operating system), operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically package manager, pac ...
available, and as such is useful for people who have to work with multiple versions of Unix. On Unix-based operating systems, some utilities like
SQL*Plus run ed as the editor if the EDITOR and VISUAL environment variables are not defined. If something goes wrong, ed is sometimes the only editor available. This is often the only time when it is used interactively.
The version of ed provided by
GNU has a few switches to enhance the feedback. Using provides a simple prompt and enables more useful feedback messages. The switch is defined in POSIX since
XPG2 (1987).
[
The ed commands are often imitated in other line-based editors. For example, ]CP/M
CP/M, originally standing for Control Program/Monitor and later Control Program for Microcomputers, is a mass-market operating system created in 1974 for Intel 8080/Intel 8085, 85-based microcomputers by Gary Kildall of Digital Research, Dig ...
's ED, EDLIN
Edlin is a line editor, and the only text editor provided with early versions of IBM PC DOS, MS-DOS and OS/2. Although superseded in MS-DOS 5.0 and later by the full-screen MS-DOS Editor, and by Notepad in Microsoft Windows, it continued to b ...
in early MS-DOS
MS-DOS ( ; acronym for Microsoft Disk Operating System, also known as Microsoft DOS) is an operating system for x86-based personal computers mostly developed by Microsoft. Collectively, MS-DOS, its rebranding as IBM PC DOS, and a few op ...
versions and 32-bit
In computer architecture, 32-bit computing refers to computer systems with a processor, memory, and other major system components that operate on data in a maximum of 32- bit units. Compared to smaller bit widths, 32-bit computers can perform la ...
versions of Windows NT
Windows NT is a Proprietary software, proprietary Graphical user interface, graphical operating system produced by Microsoft as part of its Windows product line, the first version of which, Windows NT 3.1, was released on July 27, 1993. Original ...
has a somewhat similar syntax, and text editors in many MUD
Mud (, or Middle Dutch) is loam, silt or clay mixed with water. Mud is usually formed after rainfall or near water sources. Ancient mud deposits hardened over geological time to form sedimentary rock such as shale or mudstone (generally cal ...
s (LPMud
LPMud, abbreviated LP, is a family of multi-user dungeon (MUD) server software. Its first instance, the original LPMud game driver, was developed in 1989 by Lars Pensjö (the LP in LPMud). LPMud was innovative in its separation of the MUD infrastr ...
and descendants, for example) use ed-like syntax. These editors, however, are typically more limited in function.
Example
Here is an example transcript of an ed session. For clarity, commands and text typed by the user are in normal face
The face is the front of the head that features the eyes, nose and mouth, and through which animals express many of their emotions. The face is crucial for human identity, and damage such as scarring or developmental deformities may affect th ...
, and output from ed is emphasized.
a
This is line number two.
.
2i
.
,l
ed is the standard Unix text editor.$
$
This is line number two.$
w text.txt
63
,l
ed is the standard Unix text editor.$
$
This is line number three.$
w text.txt
65
q
The end result is a simple text file text.txt
containing the following text:
ed is the standard Unix text editor.
This is line number three.
Started with an empty file, the a
command appends text (all ed commands are single letters). The command puts ed in ''insert mode'', inserting the characters that follow and is terminated by a single dot on a line. The two lines that are entered before the dot end up in the file buffer. The 2i
command also goes into insert mode, and will insert the entered text (a single empty line in our case) before line two. All commands may be prefixed by a line number to operate on that line.
In the line ,l
, the lowercase L stands for the list command. The command is prefixed by a range, in this case ,
which is a shortcut for 1,$
. A range is two line numbers separated by a comma ($
means the last line). In return, ed lists all lines, from first to last. These lines are ended with dollar signs, so that white space at the end of lines is clearly visible.
Once the empty line is inserted in line 2, the line which reads "This is line number two." is now actually the third line. This error is corrected with , a substitution command. The 3
will apply it to the correct line; following the command is the text to be replaced, and then the replacement. Listing all lines with ,l
the line is shown now to be correct.
w text.txt
writes the buffer to the file text.txt
making ed respond with ''65'', the number of characters written to the file. q
will end an ed session.
Cultural references
The GNU Project has numerous jokes around ed hosted on its website. In addition, the glibc
The GNU C Library, commonly known as glibc, is the GNU Project implementation of the C standard library. It provides a wrapper around the system calls of the Linux kernel and other kernels for application use. Despite its name, it now also dir ...
documentation notes an error code called with its description (errorstr) merely a single question mark, noting "the experienced user will know what is wrong."
See also
* Edlin
Edlin is a line editor, and the only text editor provided with early versions of IBM PC DOS, MS-DOS and OS/2. Although superseded in MS-DOS 5.0 and later by the full-screen MS-DOS Editor, and by Notepad in Microsoft Windows, it continued to b ...
, the standard MS-DOS line editor which was inspired by ''ed''
* Sam (text editor)
* Editor war
* List of Unix commands
This is a list of the shell commands of the most recent version of the Portable Operating System Interface (POSIX) IEEE Std 1003.1-2024 which is part of the Single UNIX Specification (SUS). These commands are implemented in many shells on moder ...
References
External links
*
Manual page from Unix First Edition describing ed
*
* , a direct descendant of the original ed.
section 3.1 describes the history of ed.
{{Ken Thompson navbox
Unix text editors
MacOS text editors
Standard Unix programs
Unix SUS2008 utilities
Plan 9 commands
Line editor
1971 software
Console applications