ed command in Linux with examples
Last Updated :
01 Nov, 2024
Linux ‘ed’ command is used to start the ed text editor, a very minimal fronted line-based text editor. The lines are very simple in relation to other text files, hence easy to work on, for creating as well as editing, display, and manipulation of files.
Since it was the first editor that was included in Unix, much more sophisticated editors like vi and emacs have replaced it, but it still finds many specialized applications in scripts and automated editing.
Syntax
ed [options] [file]
Here, [options] are optional flags to modify the behavior of ed, and [file] is the name of the file that you want to edit (also optional).
Basic ed Command Example
The easiest way to enter the ed text editor is with the bare command “ed” in the terminal, no options, and no filename to specify it with. This creates a new, empty buffer for you to write in.
ed

Terminal displaying ed command prompt
Key Options and Usage
Common Options
Option
|
Description
|
-p string
|
Use string as the prompt instead of the default period (.)
|
-s
|
Suppression diagnostics (schticky mode)
|
-v
|
Use verbose mode, print line numbers and error messages
|
-G
|
Enable compatibility mode with the POSIX ed utility
|
Basic ed Commands
- a – Append text after the current line
- i – Insert text before the current line
- d – Delete the current line
- p – Print the current line
- w – Write the buffer to a file
- q – Quit the editor
Detailed Usage Example
Let’s walk through an example of fully interacting with ed to compose and modify a simple text file:
Step : 1. Launch ed:
ed
Step : 2. Type a few lines, entering insert mode along the way:
a
This is line 1
This is line 2
This is line 3
.
Step : 3. Print all lines:
,p
Step : 4. Save the file:
w example.txt
Step : 5. Exit ed:
q

Terminal output with ed command sequence
Interacting with a Data File
Let’s imagine we are to use ed to make some quick edit on a CSV file named “users.csv” containing user data.
ed users.csv
,p
1,$s/John/Jonathan/g
w
q
This will:
- Open users.csv in ed
- Print all lines of the file
- Replace all “John” strings by “Jonathan”
- Write changes to the file
- Quit ed

Terminal executing ed commands to edit a CSV file
Conclusion
Compared to more modern text editors, the ed editor is certainly ancient, but it’s still a handy utility for rapid edits where large files are involved, or in tightly-constrained resources systems, such as scripts. Its line-based interface and limited command set make it perfect for automated text processing tasks. As a Linux user learns the basics of the ed editor, he can add yet another great tool to his arsenal.
Why would someone use the ed editor when they could use more modern ones?
ed is useful for quick edits, especially in scripts or on systems with limited resources. Its simplicity and consistency make it ideal for automated text processing tasks.
How does ed differ from other text editors like vi or nano?
ed is a line editor, not a full-screen editor. It has a minimal interface and uses a command-based approach, unlike vi or nano which are more interactive and visual.
Can ed be used for large files?
Yes, ed can be efficient for large files as it only loads the parts of the file you’re working on, making it memory-efficient for targeted changes in big files.
Can ed be used in shell scripts for automated text processing?
Absolutely. ed’s predictable behavior and ability to take commands through standard input make it well-suited for use in shell scripts for automated text processing tasks.
Is there a modern use case for ed where it makes more sense than to choose another text editor?
Yes, ed can be preferable in scenarios like system recovery, embedded systems with limited resources, automated log processing, and maintaining legacy systems that rely on ed’s specific behavior.
Similar Reads
enable and disable command in Linux
Enables and disables are the built-in shell commands. enable command is used to start the printers or classes whereas the disable command is used to stop the printers or classes. Syntax For enable Command: enable [-a] [-dnps] [-f filename][name ...] Syntax For disable Command: disable [-c] [-W] [ -r
1 min read
dmesg command in Linux for driver messages
dmesg command also called âdriver messageâ or âdisplay messageâ is used to examine the kernel ring buffer and print the message buffer of the kernel. The output of this command contains the messages produced by the device drivers. Usage of dmesg:When the computer boots up, there are lot of messages(
6 min read
dmidecode command in Linux with Examples
The 'dmidecode' command, short for Desktop Management Interface table decoder, is a powerful utility in Linux that retrieves detailed information about your system's hardware components. This tool reads the DMI table and presents the data in a human-readable format, making it invaluable for system a
4 min read
domainname Command in Linux With Examples
domainname command in Linux is used to return the Network Information System (NIS) domain name of the host. You can use hostname -d command as well to get the host domainname. If the domain name is not set up in your host then the response will be "none". In networking terminology, the domain name i
3 min read
dos2unix and unix2dos commands
Sometimes, you will need to move files between windows and unix systems. Window files use the same format as Dos, where the end of line is signified by two characters, Carriage Return or CR or \r followed by Line Feed or LF or \n. Unix files, on the other hand, use only Line Feed (\n). unix2dos is a
4 min read
dosfsck command in Linux with Examples
dosfsck stands for DOS File System Consistency Check and is part of the dosfstools package in Unix-like operating systems. This command diagnoses and repairs MS-DOS filesystems (FAT12, FAT16, FAT32). Before running dosfsck, it is crucial to unmount the filesystem to avoid data corruption. Syntax:dos
4 min read
dstat Command in Linux With Examples
dstat is a tool that is used to retrieve information or statistics form components of the system such as network connections, IO devices, or CPU, etc. It is generally used by system administrators to retrieve a handful of information about the above-mentioned components of the system. It itself perf
3 min read
du Command in LINUX
The du command in Linux is a powerful utility that allows users to analyze and report on disk usage within directories and files. Whether youâre trying to identify space-hogging directories, manage disk space efficiently, or simply gain insights into storage consumption, the du command provides valu
5 min read
dump command in Linux with examples
The dump command in Linux is used for backing up the filesystem to a storage device. Unlike commands that back up individual files, dump operates on entire filesystems, transferring data to tape, disk, or other storage media for safekeeping. One of its key advantages is the ability to perform increm
6 min read
dumpe2fs command in Linux with examples
dumpe2fs command is used to print the super block and blocks group information for the filesystem present on device. Can be used with ext2/ext3/ext4 filesystem for information. The printed information may be old or inconsistent when it is used with a mounted filesystem. Don't forget to unmount your
2 min read