Subject: Re: Single user mode: ed(1) or bust
To: None <email@example.com>
From: Lasse =?ISO-8859-1?Q?Hiller=F8e?= Petersen <firstname.lastname@example.org>
Date: 05/05/2007 08:58:49
I would like to join the choir of ed-ucated ed users. Ed and it's brother
ex (slightly more powerful) are easy to use - just think vi with your
eyes closed - and also very handy in scripts etc.
Jeremy C. Reed wrote:
>> Moving right along, what do *other* knowledgeable NetBSD users to edit
>> in single user mode?
>echo, cut, sed, mv, cp, cat, grep :)
Yes, but you forgot one important tool: sh :-)
I have sometimes found myself in a position where I could not start any
new processes, or for other reasons unable to use ed, or much else for
that matter. For those situations it is good to know a few tricks, and I
am sure many of you know more of them than I do.
Poor man's ls:
Poor man's cat:
while read l ; do echo $l ; done <filein >fileout
I guess you must use a shell that doesn't spawn subshells for loops (I
think POSIX actually allows that?), but in practice, /bin/sh, /bin/ksh
and bash seem to be just fine.
In the situation where these things are necessary, it is also great to
know that kill is a builtin of most shells, but how do you find a process
to kill without being able to start ps? Well, if you are lucky you run
some stuff that records pids to /var/run, so that's a good place to look.
Killing all Apache httpd processes on a stressed webserver just might do
some good. (BTW, it seems that /bin/sh has kill as a built-in, but the
manpage doesn't seem to mention it? Should I file a bug?)
Now, what is a good candidate for poor man's ed?
Of course, poor man's cat can be used to read from the console, and that's
what I have used so far, retyping rather than really editing - but I am
curious whether anyone has bothered to figure out a way to use only shell
(and only a single process) to fix a few lines in an existing file?
I prefer knowing just these tricks, including ed, rather than relying on
"preparations", such as the /root/.termcap suggested by Joerg Niendorf. In
my opinion, the situations where you need it are rare enough, that it's not
worth the bother, and chances are, when you do need it, Murphy will ensure
that you'll need it on a system which you hadn't prepared anyway.