Live data from Hacker News

What typing ^D does on Unix (2009)

utcc.utoronto.ca

91–100 of 162 posts

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

#91
post #25

^U will clear the buffer - super convenient for retrying botched passwords.

In readline, ^U will only clear from the cursor to the start of the line, leaving anything on the right. ^K is the converse. I'm not sure you are speaking about readline though. Another very useful thing I use daily is Alt-F/B, to move forward/backward in the line one word at a time. Control does the same, one letter at a time. D will delete an element instead.

To add to that, C-P will go up in your history and C-N down. It is extra useful when using GDB in TUI mode (which is activated using C-x,a), which will capture your UP/DOWN arrow to navigate the source...

Actually, just go read http://ss64.com/bash/syntax-keyboard.html or something, once per day, integrate a new one each time, and you will improve your productivity on the command line (as well as comfort).

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

#92
post #57

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

^\ 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?

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

#93

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 is the old school way of writing it; you'd see it so much you'd only ever once be confused about it, generally in the very first few days you were learning to use a computer. It's never used anymore, I suppose, except for the old school people who still have enough muscular memory built up to write it that way. I know I do; I learned it from some computer magazine in the 80's and have a hard time letting go.

I dunno if I'd say it was never used anymore. Try running `cat` (to bring up a basic termainal input) and type various control keys. Anything that isn't interpreted by the tty is probably displayed using caret notation.

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

#95

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?

> Also ^| (as in, "control pipe") which is a synonym for ^\. At least for me, | is faster to hit than \

How? Do you have a keyboard where | isn't Shift+\?

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

#96
post #54

^U will clear the buffer - super convenient for retrying botched passwords.

Fun trick: If somebody is watching you type in your login password or SSH pubkey password, spaz wildly on the keyboard, frantically typing random characters, and then hit ^U and type in your real password. Then you give them a puzzled look once you successfully log in as if nothing out of the ordinary just happened and say something like "What, don't you have a sufficiently complex password?".

As long as you don't hit space you can do the same thing with ^W, as ^W will clear out the last 'word'. I use it all the time at password prompts, and more comfortable to hit than ^U.

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

#97
Directly after reading the title the question "what does ^D do" was fired at a Old Unix Beard friend of Mine who happens to be here for coffee.

Instant reply Without any latency: "It originally was meant to terminate the Tape drive"

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

#98
The author actually clouds what and why is really happening a bit. Ctrl+D sends the EOF character to the terminal driver. The terminal driver then determines, based on its settings, what to do next.

In the 'icanon' mode, the terminal driver implements a rustic line editor, so you can do things like Backspace to delete previous characters and so on. Pressing Enter during this mode returns the edited buffer line to the program.

Where Ctrl+D, or EOF, comes in is when you want to return a line to the program _without_ pressing Enter. This is where the terminal driver returns the buffer to the read() function for the program immediately. Doing it again with no additional input shows that you were done line-editing, so it simply returns nothing, signaling the program that you're done editing or providing input - the intended purpose of End Of File, the character sent by Ctrl+D. (If you were reading a file and you received nothing on a read... you would be at the end of a file, because why else would the file have nothing else to read?)

But this 'icanon' mode won't be active in your actual terminal shell, because shells have their own line editing implementation, so they turn 'icanon' off by default. You can, of course, turn on or off in the terminal with "stty". Use "stty -a" to see all the other current settings. The terminal application, by the way, sets the EOF to the same value as the terminal driver's by default, in order to prevent confusion.

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

#99
post #97

Directly after reading the title the question "what does ^D do" was fired at a Old Unix Beard friend of Mine who happens to be here for coffee. Instant reply Without any latency: "It originally was meant to terminate the Tape drive"

[citation needed] I suspect they're misremembering what the T in EOT stands for.

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

#100
post #64

As a corollary, typing ^D twice on a non-empty line will also send EOF on the input, allowing you to provide a program with input not ending with \n from the command line. I knew about this behavior, but not why it worked, but this article's explanation clarifies this behavior as well. The first ^D terminates the read() call, passing the line so far, without terminating \n, to the program. The second causes read() to…

A super easy way to see this is to type cat, and then type asdf and hit ^D. It immediately echoes back what you typed. Another ^D quits cat, because it gets a 0-byte read that time.

This was cool. Thanks for sharing!
Post reply on HN