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.
Sull'autore
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).
Ricerca per canale
Automazione
Novità sull'automazione IT di tecnologie, team e ambienti
Intelligenza artificiale
Aggiornamenti sulle piattaforme che consentono alle aziende di eseguire carichi di lavoro IA ovunque
Hybrid cloud open source
Scopri come affrontare il futuro in modo più agile grazie al cloud ibrido
Sicurezza
Le ultime novità sulle nostre soluzioni per ridurre i rischi nelle tecnologie e negli ambienti
Edge computing
Aggiornamenti sulle piattaforme che semplificano l'operatività edge
Infrastruttura
Le ultime novità sulla piattaforma Linux aziendale leader a livello mondiale
Applicazioni
Approfondimenti sulle nostre soluzioni alle sfide applicative più difficili
Serie originali
Raccontiamo le interessanti storie di leader e creatori di tecnologie pensate per le aziende
Prodotti
- Red Hat Enterprise Linux
- Red Hat OpenShift
- Red Hat Ansible Automation Platform
- Servizi cloud
- Scopri tutti i prodotti
Strumenti
- Formazione e certificazioni
- Il mio account
- Supporto clienti
- Risorse per sviluppatori
- Trova un partner
- Red Hat Ecosystem Catalog
- Calcola il valore delle soluzioni Red Hat
- Documentazione
Prova, acquista, vendi
Comunica
- Contatta l'ufficio vendite
- Contatta l'assistenza clienti
- Contatta un esperto della formazione
- Social media
Informazioni su Red Hat
Red Hat è leader mondiale nella fornitura di soluzioni open source per le aziende, tra cui Linux, Kubernetes, container e soluzioni cloud. Le nostre soluzioni open source, rese sicure per un uso aziendale, consentono di operare su più piattaforme e ambienti, dal datacenter centrale all'edge della rete.
Seleziona la tua lingua
Red Hat legal and privacy links
- Informazioni su Red Hat
- Opportunità di lavoro
- Eventi
- Sedi
- Contattaci
- Blog di Red Hat
- Diversità, equità e inclusione
- Cool Stuff Store
- Red Hat Summit