For as well-loved as the vi
command is, it's the ed
command that's considered the standard Unix text editor. It was the very first text editor for Unix, and it's available on even the most modern Linux systems.
Unlike text editors you may be used to on Linux or another system, ed
doesn't open a window or even a screen of its own. That's because it's a functional editor that you can control either interactively or with a script. If you're already familiar with sed
, then you'll find ed
easy to learn. If you're new to both, ed
can give you a different perspective on how you can process and modify data on your system.
Launch ed
Launching ed
is easy; just enter the command at the prompt:
$ ed
When you first launch ed
, you get no feedback or prompt. That's the expected behavior, so don't panic. Your system hasn't crashed, ed
is just waiting for your instructions.
To get ed
to be a little more visual, use the p
command to create a prompt. Type the letter p
followed by the Return or Enter key:
$ ed
p
?
The question mark (?
) is the default ed
prompt.
Use the ed buffer
While ed
is active, it uses a place in memory to store data. This location is called a buffer. Such storage is significant because you're not editing a file directly. You're editing a copy of file data placed into the buffer. As long as you save the buffer when you're done, ed
preserves any changes you make to the data.
If you exit ed
without writing changes to a file on disk, it loses all changes because they only existed in the buffer. It's no different than closing any application without saving changes, but ed
doesn't warn you, so keep this in mind.
Generate text with ed
Similar to the vi
editor, ed
starts in command mode. This means you can issue commands to the editor, as you did to display a prompt, but you can't write or edit text without issuing a command first.
You can append text to the current buffer using the a
command followed by the Return or Enter key. Whatever text you type into the terminal now will be appended to the buffer. Stop ed
from appending text to the buffer by typing a solitary dot (.
) on its own line.
This example adds two lines ([myconfig]
and widget=True
) to the buffer:
?
a
[myconfig]
widget=True
.
After a terminating dot, ed
returns to command mode.
Save the buffer to disk
Once you're happy with your text, you can write the buffer to a file using the w
command followed by the destination file's name:
?
w myconfig.txt
23
As confirmation, it outputs the number of characters written to the file.
Read an ed file
You will probably use ed
to edit existing config files more often than you use it to write new text files from scratch. To load a file into the buffer, enter ed
followed by the name of the file you want to load:
$ ed myfile.txt
From within ed
, you can open an existing file into the buffer using the r
command:
?
r /etc/myconfig.txt
[ Download the Linux commands cheat sheet. ]
View the buffer
To see all lines in the buffer, type ,p
and then press Return:
?
,p
[myconfig]
widget=True
To see just a specific line, type the line number:
?
1
[myconfig]
2
widget=True
Edit the buffer
To edit a file, first load it in the buffer:
$ ed myconfig.txt
,p
[myconfig]
widget=True
foo=bar
openssl=libssl
To change the word "True" to "False" in the first setting of this file, select the line you want to target (2) and then invoke the search function by entering s
followed by the replacement term:
?
2
widget=True
s/True/False/
2
widget=False
To target another line, use a different line number and search terms:
?
4
openssl=libssl
s/libssl/libgnutls/
s/openssl/ssl/
View the edits you've made to the buffer using the ,p
command:
[myconfig]
widget=True
foo=bar
ssl=libgnutls
You haven't written the buffer back to the file yet, so the altered lines exist only in memory. To save your changes back into the file, use the w
command:
w myfile.txt
45
Clear the buffer
To start a new document or load one into a clean environment, you must clear out the buffer. The c
command clears the buffer, which you can verify using the print command (,p
):
c
,p
Quit ed
There are two common ways to end an ed
session: you can press Ctrl+D or you can type the q
command. This doesn't give you a chance to save your buffer, so make sure you've written data you want to keep out to a file!
Get to know ed
If nothing else, learning ed
is a powerful safeguard against getting left without a text editor when your system is in a state of recovery and you're left with only the most basic toolset. This happened to me once, and I was able to fix an errant configuration file only because I had just enough recollection of using ed
in a Linux course I'd taken at a community center long ago.
It's true that ed
might be the last resort, but it's nice to know what to do with the command when it's your one and only choice. And even if you don't anticipate needing ed
(even in an emergency) it's a fun command to explore and gives you a good understanding of how tools like vim
and sed
came about. Use info ed
to view the full manual to learn more.
Über den Autor
Seth Kenlon is a Linux geek, open source enthusiast, free culture advocate, and tabletop gamer. Between gigs in the film industry and the tech industry (not necessarily exclusive of one another), he likes to design games and hack on code (also not necessarily exclusive of one another).
Nach Thema durchsuchen
Automatisierung
Das Neueste zum Thema IT-Automatisierung für Technologien, Teams und Umgebungen
Künstliche Intelligenz
Erfahren Sie das Neueste von den Plattformen, die es Kunden ermöglichen, KI-Workloads beliebig auszuführen
Open Hybrid Cloud
Erfahren Sie, wie wir eine flexiblere Zukunft mit Hybrid Clouds schaffen.
Sicherheit
Erfahren Sie, wie wir Risiken in verschiedenen Umgebungen und Technologien reduzieren
Edge Computing
Erfahren Sie das Neueste von den Plattformen, die die Operations am Edge vereinfachen
Infrastruktur
Erfahren Sie das Neueste von der weltweit führenden Linux-Plattform für Unternehmen
Anwendungen
Entdecken Sie unsere Lösungen für komplexe Herausforderungen bei Anwendungen
Original Shows
Interessantes von den Experten, die die Technologien in Unternehmen mitgestalten
Produkte
- Red Hat Enterprise Linux
- Red Hat OpenShift
- Red Hat Ansible Automation Platform
- Cloud-Services
- Alle Produkte anzeigen
Tools
- Training & Zertifizierung
- Eigenes Konto
- Kundensupport
- Für Entwickler
- Partner finden
- Red Hat Ecosystem Catalog
- Mehrwert von Red Hat berechnen
- Dokumentation
Testen, kaufen und verkaufen
Kommunizieren
Über Red Hat
Als weltweit größter Anbieter von Open-Source-Software-Lösungen für Unternehmen stellen wir Linux-, Cloud-, Container- und Kubernetes-Technologien bereit. Wir bieten robuste Lösungen, die es Unternehmen erleichtern, plattform- und umgebungsübergreifend zu arbeiten – vom Rechenzentrum bis zum Netzwerkrand.
Wählen Sie eine Sprache
Red Hat legal and privacy links
- Über Red Hat
- Jobs bei Red Hat
- Veranstaltungen
- Standorte
- Red Hat kontaktieren
- Red Hat Blog
- Diversität, Gleichberechtigung und Inklusion
- Cool Stuff Store
- Red Hat Summit