Live data from Hacker News

What typing ^D does on Unix (2009)

utcc.utoronto.ca

151–160 of 162 posts

Re: What typing ^D does on Unix (2009)

#151

Earlier quoted context omitted.

... There's a program called SSH to get to another CPU. Tilde is the escape, it's doubled to send it through, And "quit" is tilde-. I think you know how the rest goes...

What does this reference?

It references "The TELNET Song" by Guy L. Steele (a.k.a The Great Quux). The original is about Telnet, and given the subject of discussion, the reference seemed a natural one to make.

Re: What typing ^D does on Unix (2009)

#152
If memory serves well, there was also the amazing Ctrl-O, which allowed you to send control sequences over a busy terminal --for example when scrolling a lot of text, seems to be mapped to the arcane VDISCARD and unsupported by Posix & Linux.

Re: What typing ^D does on Unix (2009)

#153
post #43

I wish articles like this would say what ^D means. I remember when I was new to Unix it took me a while to realize that I wasn't supposed to type a literal caret (^) followed by a D. For reference it means Ctrl+D, unless you you have a strange keyboard from Sun or something.

^D, Ctrl+D and C-d are all different ways of saying the same thing. There's nothing particularly neutral about Ctrl+D, any more than there is about using the word 'water' to mean the substance of which the oceans are mostly comprised — it's just another dialect's term.

> ^D, Ctrl+D and C-d are all different ways of saying the same thing.

Right, and the classic book The Unix Programming Environment (by Brian Kernighan and Rob Pike) uses ctl-d.

Re: What typing ^D does on Unix (2009)

#154
post #57

Expanding on this, ^\ (Ctrl+\) means sigkill, and I don't think many people know about this one.

IIRC, on Unix, Ctrl-\ sends the quit signal, which causes the process receiving it to do a core dump (before exiting), which can be used for post-mortem debugging, whereas Ctrl-C sends the kill signal, which makes the process terminate without any core dump. Those are the default actions for the signals.

https://en.wikipedia.org/wiki/Control-%5C

https://en.wikipedia.org/wiki/Core_dump

https://en.wikipedia.org/wiki/Control-C

I remember doing:

sdb a.out . core

or something like that, in my C-on-Unix programming days earlier :)

sdb was a debugger.

Re: What typing ^D does on Unix (2009)

#155
post #154
post #57

Expanding on this, ^\ (Ctrl+\) means sigkill, and I don't think many people know about this one.

IIRC, on Unix, Ctrl-\ sends the quit signal, which causes the process receiving it to do a core dump (before exiting), which can be used for post-mortem debugging, whereas Ctrl-C sends the kill signal, which makes the process terminate without any core dump. Those are the default actions for the signals. https://en.wikipedia.org/wiki/Control-%5C https://en.wikipedia.org/wiki/Core_dump https://en.wikipedia.org/wiki/Co…

Speaking of terminating Unix processes, here's a post I wrote a while ago:

UNIX one-liner to kill a hanging Firefox process:

http://jugad2.blogspot.in/2008/09/unix-one-liner-to-kill-han...

Some interesting comments on that post too, which go into slightly deeper details.

Re: What typing ^D does on Unix (2009)

#156

Earlier quoted context omitted.

For the vi-adherents out there, `set -o vi` will let you navigate your prompt and history with vi-like keybindings. I'm amazed by how many vi users don't know this.

I'm amazed by how many people still run bash!

Why wouldn't they it is one of the defacto standards? You use what you know most of the time.

Re: What typing ^D does on Unix (2009)

#158
post #105

Neat. So when my terminal is spewing output because I ran "cat massivefile" instead of "cat massivefile | head", I can hit ctrl-D to stop it instead of repeatedly hitting ctrl-C and despairing.

No, thats what ctrl-s and ctrl-q are for. Here's the rest in one place: eof VEOF EOF character eol VEOL EOL character eol2 VEOL2 EOL2 character erase VERASE ERASE character erase2 VERASE2 ERASE2 character werase VWERASE WERASE character intr VINTR INTR character kill VKILL KILL character quit VQUIT QUIT character susp VSUSP SUSP character start VSTART START character stop VSTOP STOP character dsusp VDSUSP DSUSP chara…

Nice. Reminds me of using the "stty -a" and "stty " commands many times on Unix terminals, back in the day, for some of those settings you list, also for things like CR/LF translation (ocrnl, onlcr, ...), raw, sane, ...

Re: What typing ^D does on Unix (2009)

#159
post #114

Neat. So when my terminal is spewing output because I ran "cat massivefile" instead of "cat massivefile | head", I can hit ctrl-D to stop it instead of repeatedly hitting ctrl-C and despairing.

Also, a side note, I would rather just run "head massivefile" or even better "less massivefile" (because, most probably I'd want to see past what head shows by default). Running cat and then piping it to another program is inefficient, 2 forks + pipe.

And on systems where head was not present (seen some earlier), but sed was, you could do:

sed nq file

where n is some positive integer, to print the first n lines of the file.

Also, body (the complement of head and tail :)

# body

sed -n $1,$2p $3

Re: What typing ^D does on Unix (2009)

#160
post #30

Earlier quoted context omitted.

As the article explained at the end, shells put the terminal into uninterpreted mode, so ^D doesn't do anything special there. You have to be using a program (such as cat) that doesn't do this to see ^D's behavior.

Shells that want to implement features like tab completion or more elaborate line editing than the basics, which only provide for deleting the last character, word, or line (using Backspace/^W/^U) need to put the terminal into raw mode when reading the user's command line so they can bypass the basic line editing that the terminal provides (called "cooked mode"). However, you can write a shell that doesn't do this. I…

I didn't realize Dash uses cooked mode. That's actually kind of surprising; every other shell I've used always uses raw mode to give them more control over line editing. Is Dash just trying to be as minimalistic as possible?
Post reply on HN