ed
Edit text files line-by-line
TLDR
Start an interactive editor session with an empty document
Start an interactive editor session with an empty document and a specific prompt
Start an interactive editor session with user-friendly errors
Start an interactive editor session with an empty document and without diagnostics, byte counts and '!' prompt
Start an interactive editor session without exit status change when command fails
Edit a specific file (this shows the byte count of the loaded file)
[Interactive] Replace a string with a specific replacement for all lines
[Interactive] Exit ed
SYNOPSIS
ed [options] [file]
PARAMETERS
-G, --traditional
Use POSIX basic regular expressions (BRE).
-s, --quiet, --silent
Suppress diagnostics, byte counts, and '!' prompt.
-p string, --prompt=string
Set editor prompt to string (default '?').
-l, --loose-exit-status
Exit 0 unless fatal error, even on command failure.
-r, --restricted
Restricted mode: no shell escapes or file writes outside original.
-S script, --script=script
Execute commands from script file at startup.
-t tag, --tag=tag
Jump to line with tag from 'tags' file.
-v, --version
Print version information and exit.
-h, --help
Print usage summary and exit.
DESCRIPTION
ed is the original Unix text editor, a modal, line-oriented tool for editing text files via command line instructions. It operates on a buffer of numbered lines, using terse single-letter commands preceded by optional addresses (line numbers, ranges like 1,$, or patterns like /foo/). Default mode is command mode; enter input mode with a (append), i (insert), or c (change), exiting with a single dot . on a blank line.
Key commands: p (print), = (line number), n (line with number), d (delete), y (yank), u (undo), w (write file), q (quit), ! (shell escape), g/pat/cmd (global on pattern), v/pat/cmd (global not matching), s/old/new/ (substitute).
Ed reads files into memory, supports scripting for batch edits, and is POSIX-mandated. It's scriptable progenitor of sed and basis for ex/vi. Minimal footprint suits embedded systems; customizable prompt aids interaction. Type H for help, h for error explanation.
CAVEATS
Terse syntax requires memorization; limited undo (single-level u); no visual feedback or syntax highlighting; modal nature confuses beginners; memory-limited for huge files; always w before q to avoid loss.
INPUT MODE EXIT
End append/insert/change with lone . on line.
H for full help; h explains errors.
ADDRESSES
., $ (last), % (all), /re/ (search forward), ?re? (backward); ranges like 5,10; 0 for before first.
HISTORY
Created by Ken Thompson in 1971 for 1st Edition Unix at Bell Labs. Standardized in POSIX.1; GNU ed by Antonio Diaz Diaz since 1999 adds extensions while preserving compatibility. Basis for ex (1976, Bill Joy) and vi.


