Live data from Hacker News

What typing ^D does on Unix (2009)

utcc.utoronto.ca

121–130 of 162 posts

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

#121
post #116
post #60

Earlier quoted context omitted.

Darnit, I had to dial in again. Kidding of course, but once upon a time many 56k6 modem contained a bug that, upon receiving this in plain text, would cause an actual modem hangup. You could kill hundreds of IRC connections with that one.

It wasn't exactly an unintentional bug - rather one company owned a patent on the technique of enforcing a guard time before and after the attention string to go into command mode (the Hayes '302 patent). They licensed it for $1/modem, but some manufacturers felt that they couldn't afford that.

Ha, I never knew! Thanks for adding this; who would have thought my 20 year old anekdote would get a refreshment. :-)

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

#122
post #24

Pressing enter then ~. will gracefully shutdown hung ssh sessions

More generally, type ~ as an escape sequence. For example, type ~^Z to put a session in the background. Similarly, type ~~ to send an escape sequence in an inner session, etc...

Or type ~? for a list of escapes.

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

#123
post #74

Earlier quoted context omitted.

Something I use extensively in terminals is ^L and ^M. ^L clear the screen and ^M for a line return.

I'm not proud of this, but I sometimes bounce between ^N (next-line in emacs) and ^I (tab character, bound to various thing in different emacs modes) to re-indent a region. I usually only do this for <10 lines. More than that and I go look up the function that does it 'right'.

Why not proud? Sounds fast and efficient. I didn't save the move of the hand to the tab key, but I will now. Thanks.

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

#124
post #117
post #45

Earlier quoted context omitted.

It's not about neutrality, it's about ease of understanding. For me at least, when speaking about something that can be entered into a keyboard ^D is less obvious than Ctrl+D–I need to press the key labeled "control" to issue the proper command, the key labeled "^" will not suffice.

Even then though, why is it obvious that you don't need to press the key labelled + as well?

All I know is that in my youth ^ sent me to google befuddled a few times while + never did

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

#125
post #112

Earlier quoted context omitted.

I am amazed by the fact that I never accidentally trigger this feature.

You'd probably trigger it more often if ~/ didn't conveniently map to ~/ - it's quite cleverly designed in a way. Indeed, most of the two-character combinations you're likely to type starting with ~ map to themselves.

It's annoying when you're adminning users and atually want to type "~user/foo" though.

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

#126

Earlier quoted context omitted.

To be really pedantic (sorry! I'm not complaining about your comment), your keyboard does not have any key labelled 'control', it is always (AFAIK) abbreviated as 'ctrl'. Which is really weird to me, as it's hardly a big word needing abbreviating, and keyboards often have other long words written on the keys ('delete', 'page down', and so on). On top of that, the shortened 'ctrl' is really a terrible abbreviation. It…

You're incorrect, especially for the typical reader here. A good chunk (maybe not over 50%, but its gotta be close) of the regular readers on this site use Macs. Most Mac keyboards, including the ones on the Macbook Pro, spell it out. Same for most non IBM/IBM-PC compatible keyboards.

My mid 2014 MBP control key is labeled "control"

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

#127
No TTY-related discussion is complete without a reference to Linus Akesson's extremely lucid article on the whole thing, including what all the other interesting Ctrl+ characters do:

http://www.linusakesson.net/programming/tty/

...and the extensive previous HN discussion on it:

https://news.ycombinator.com/item?id=10631513

https://news.ycombinator.com/item?id=10064657

https://news.ycombinator.com/item?id=8094186

https://news.ycombinator.com/item?id=4544318

https://news.ycombinator.com/item?id=4062981

https://news.ycombinator.com/item?id=658155

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

#128
post #65
post #14

Earlier quoted context omitted.

Actually the remote sshd does not need to be responsive, because " ~." is interpreted by the local ssh client. Very convenient if the TCP connection is stuck. You can also type " ~?" for a list of other commands supported by the local ssh client. Among other things, " ~C" opens a command line interpreter on the client side of the ssh client, allowing you to add and remove TCP port forwarding without restarting the co…

Ahg, I wish it let you scp files into your working directory too. That's be convenient.

Long ago I sent a patch for uploading downloading using this escape sequence, using zmodem like how an old windows SSH client (I forget the name) used to allow uploading/downloading files.

You log in, type "rz", and then use escape sequence to upload a file. (similar for downloading)

The patch was rejected. Shame. It's very useful when hopping 6 steps to upload a file.[1]

I can't find the patch now, but I'm considering rewriting it as a an `expect` script. My `expect` scripts tend to have trouble with SIGWINCH propagation though, so not optimal. Also you have to remember to wrap with the `expect` script at (and preferably only at) the one "jump" you want to send from/to with the final destination.

[1] No, nothing illegal. Just that some networks mandate SSH jumpgates, and sometimes multi-level.

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

#129

Earlier quoted context omitted.

^\ is actually sigquit, which is a bit different from sigkill, since programs can catch QUIT and perform some cleanup.

Also ^| (as in, "control pipe") which is a synonym for ^\. At least for me, | is faster to hit than \ And since we're on this topic: if I write a for loop in bash that runs a slow command 1000 times (ImageMagick comes to mind), and I realise something has gone wrong, is there an easy way of breaking the outer loop?

Not a nice way, but the way that works best for me is:

^Z

fg

^C

the ^Z kills the loop, the fg and ^C cleans up the currently running one.

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

#130
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.

But you miss out on this award if you don't use cat :p http://porkmail.org/era/unix/award.html
Post reply on HN