ed

file managementLinux/Unix
The ed command is one of the most frequently used commands in Linux/Unix-like operating systems. ed Line-oriented text editor

Quick Reference

Command Name:

ed

Category:

file management

Platform:

Linux/Unix

Basic Usage:

ed [options] [arguments]

Common Use Cases

  • 1

    Script-based editing

    Edit files programmatically in shell scripts

  • 2

    Minimal environment editing

    Edit text files in recovery or limited environments

  • 3

    Legacy system maintenance

    Maintain compatibility with older Unix scripts and systems

  • 4

    Regular expression processing

    Process text using powerful regular expressions

Syntax

ed [options] [file]

Options

Option Description
-G Force backward compatibility with historic versions of ed
-p string Specify a command prompt
-r Use restricted mode (cannot execute shell commands)
-s Suppress diagnostics (quiet mode)
-v Verbose mode (displays file size and other information)

Examples

How to Use These Examples

The examples below show common ways to use the ed command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

# Basic Examples Basic
ed filename.txt
Edit a file named filename.txt.
ed
Start ed without any file.
# Advanced Examples Advanced
ed -p "ed> " filename.txt Start ed with a custom prompt. # Inside ed commands: # a - append text # i - insert text # d - delete lines # p - print lines # w - write to file # q - quit a This is a new line. . w newfile.txt Write buffer to newfile.txt. q Quit ed.

Try It Yourself

Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

Understanding Syntax

Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

Notes

Ed is the original Unix text editor, a line-oriented editor that operates on a copy of the file being edited. It's extremely minimalist and operates through single-letter commands. Despite its simplicity, ed is very powerful and remains useful for scripting or when working in limited environments. It's often found in recovery environments or minimal system installations. Common 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 - n: Print the current line with line number - w: Write buffer to file - q: Quit ed - Q: Force quit without saving - s/old/new/: Substitute text - /pattern/: Search forward for pattern - ?pattern?: Search backward for pattern Inputs to ed commands are terminated by a single period (.) on a line by itself.

Tips & Tricks

1

Use the -p option to set a custom command prompt

2

Use a single dot (.) on a line by itself to end input mode

3

Use line numbers or patterns to specify which lines to edit

4

Use the s/old/new/ command to find and replace text

5

Use w filename to write changes to a different file

Common Use Cases

Script-based editing

Edit files programmatically in shell scripts

Minimal environment editing

Edit text files in recovery or limited environments

Legacy system maintenance

Maintain compatibility with older Unix scripts and systems

Regular expression processing

Process text using powerful regular expressions

Emergency file editing

Edit configuration files when other editors are unavailable

Related Commands

These commands are frequently used alongside ed or serve similar purposes:

Use Cases

1

Script-based editing

Edit files programmatically in shell scripts

2

Minimal environment editing

Edit text files in recovery or limited environments

3

Legacy system maintenance

Maintain compatibility with older Unix scripts and systems

4

Regular expression processing

Process text using powerful regular expressions

5

Emergency file editing

Edit configuration files when other editors are unavailable

Learn By Doing

The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the ed command works in different scenarios.

$ ed
View All Commands