Table of Contents
Acknowledgements
My entire careerindeed, modern life for every one of uswould not have been possible without those giants who wrote entire operating systems using ed and its predecessors. We owe those giants a debt of gratitude.
More personally, though, I want to thank my technical reviewers who were kind enough to share their immense edpertise: Tim Chase, Josh Grosse, and Kurt Mosiejczuk. Any errors in this book crept in despite these fine folks best efforts.
Many examples in this book were inspired by the fine presentations at the ed(1) Conference, available on Twitter at https://twitter.com/ed1conf and on Mastodon at https://bsd.network/@ed1conf. Attending the worlds premier conference for text editing at 300 baud will help keep your ed skills razor-sharp.
After receiving rare but tediously ongoing complaints about mixed male and female third-person pronouns in technology books, the author has prepared two editions of this book. Any third-person singular pronouns that appear in the standard edition, for normal people, are female. Those who believe that women dont belong in tech books are welcome to purchase this special Manly McManface edition, where all third-party singular pronouns are masculine. To compensate for this editions much smaller market, though, the Manly edition is pricier than the standard edition. Thats basic economics.
Also, one dollar of the authors proceeds from each sale of the Manly McManface Edition will be donated to his local chapter of Soroptimists International.
Chapter 0: Introduction
Let me be very clear here: ed(1) is the standard Unix text editor.
Dennis Ritchie, co-creator of Unix, declared it so. Who are you to argue with someone who can write a complete operating system without using a glass teletype?
Many younger sysadmins naively hoist their pennants to defend overblown, overwrought, overdesigned text editors like ex, vi, or even the impossibly bloated nvi. A few are so lost as to devote themselves to turgid editors meant for mere users, such as vim and Emacs. This way lies not only appalling sysadmin skills, but an absence of moral fiber. As a sysadmin, you must have enough brain power to remember what you typed, to hold your own context in your head, and to truly commune with the machine on a deep and personal level.
Most Unix hosts exist to perform real work, such as supporting databases or serving web pages. When you specced out the systems memory, processor, and disk I/O, you considered the amount of hardware needed to run those tasks. Any system resources above that are intended to support atypical peak loads, not some pathetically overengineered text editor. When you suck up extra kilobytesor, worse, megabytesto run a fancy editor, you steal from the host.
Sysadmins dependent on something like vim? They actively harm systems. Do not trust them.
For a random user, theres no shame in being unable to use ed. Im not qualified to become a Navy SEAL. Im not even qualified to become the kind of seal that lies on a beach and barks. Thats okay. The world is full of computers. If you cannot handle the undiluted glory that is ed, use one of those friendly pointy-clicky systems. Youre who they exist for. I recommend those tablet computers that dont have a keyboard, though, as those bright, colorful icons are very helpful to the non-educatable.
Its not that using ed(1) is the pinnacle of systems administration achievement; its the minimum requirement. You must be this competent to manage this computer.
If youre reading this book, its because you want to join the elite. You want to count amongst the Navy SEALS of information technology. You want to be a real sysadmin, not one of those posers that need fancy toys like a monitor. Yes, I own monitors, but only because these wimpy modern laptops dont come with built-in line printers.
Real sysadmins not only can work, they truly thrive on their wits and line printers alone. We welcome anyone who proves worthy of joining us.
This book covers standard ed. Many operating system developers cant resist the urge to add additional features to ed. Thats how the tragedies of ex and vi happened, after all. While these developers urge to become part of something as momentous as ed is perfectly understandable, ed is feature complete. This book wont cover OS-specific extensions, such as Linuxs x and y commands and FreeBSDs encryption support.
I should warn you, though: some sysadmins object to this book. They sincerely believe that the best sysadmins learn from studying the operating system source code or, at worst, reading the man page. Many of those folks forget their own youth, though. You cant learn computing on your own. Even the most sagacious Unix admins had mentors.
In this bleak age when search engine algorithms dredge up shoddily-assembled HOWTOs and pass them off as authoritative documents, providing for the next generation of sysadmins is one of the most vital tasks we face as a profession. I dont want the servers storing my retirement funds managed by so-called sysadmins who struggle against the pomposity of ex(1). Study the ed(1) source with this book at your side, in combination with a good C reference, such as the 1978 edition of The C Programming Language by the esteemed Brian Kernighan and Dennis Ritchie. If they could write a complete operating system using a line printer for output, you can handle your itty-bitty tasks.
Only a jerk would belittle you for attempting to transcend your limitations and become a proper sysadmin. Sadly, due to social stigma, I cant blame you if you hold owning this book a precious secret. If necessary, you can get instructions for making a protective book cover out of a brown paper bag from your nearest Gopher site.
Real sysadmins understand how the computer works. We understand that the long-sought What You See Is What You Get (WYSIWYG) editor is nothing but a pernicious lie from the marketing department. We know in our bones that a file ending in .txt isnt necessarily a text fileindeed, that a text file can have any name. Transcending these deceits is a necessary step to achieving true sysadmin mastery. The standard Unix editor does not pretend to be anything other than an engine for manipulating text.
And what a magnificent engine it is.
You know, a glass teletype. That toy that kids keep calling a monitor, even though we all know monitors are reference speakers used in audio production.
Why add encryption to ed? Thats what crypt(1) is for.
Chapter 1: Ed Essentials
At its heart, ed(1) is a text editor. It was written when computers didnt have monitors, though. Computers could write data to tape or to a printer. The printers of that day didnt wastefully run whole sheets of paper at a time, though; like ticker tape machines and typewriters, these line printers printed a single line at a time.
The sysadmin would enter commands, printing results only when necessary. Or, if you prefer, a clattering printer announced to everyone within hearing every time you lost your train of thought. Real sysadmins can concentrate on their work and remember context.
Ed is a line editor. It works on lines of text, as printed by a printer. Itll work perfectly well on one of those new-fangled monitor things, if youre unlucky enough to be stuck with one.
Well begin exploring ed with a few basic tasks: starting the program, considering modes, saving, and quitting.
Starting Ed
Run ed(1) by entering ed and the name of the file you want to edit. Here I want to edit a text file containing my favorite poem, Lewis Carrolls