News for hackers. Stuff that matters.
Re:What typing ^D does on Unix (2009) by gtrubetskoy on Tuesday September 06, 2016 @01:58PM (#12437906)
^U will clear the buffer - super convenient for retrying botched passwords.
Re:What typing ^D does on Unix (2009) by spudlyo on Tuesday September 06, 2016 @03:57PM (#12438837)
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?".

Re:What typing ^D does on Unix (2009) by pritambaral on Wednesday September 07, 2016 @03:49AM (#12441513)
> "What, don't you have a sufficiently complex password?"

<anecdote> I actually had a sufficiently complex password, but this one time I was in a massive hurry to demo something to my teammates, I made a mistake somewhere near the end of it, quickly typed ^U, fed it all over again, made another mistake near the end, another quick ^U, and third time was the charm.

They didn't notice that I reset the password field twice, to them it was just a mega-super-duper-long password (the actual password is 20+ characters), and one of them burst out saying, "Woah! He just wrote a short story!" </anecdote>

Re:What typing ^D does on Unix (2009) by vacri on Tuesday September 06, 2016 @05:48PM (#12439510)
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) by andromeduck on Tuesday September 06, 2016 @10:50PM (#12440707)
It's easier if you switch Ctrl and Caps because they n it just looks like you're just using the shift key.
Re:What typing ^D does on Unix (2009) by Practicality on Tuesday September 06, 2016 @04:24PM (#12439042)
I would like to recommend against spazing wildly at work.

Edit: It was just a joke :(

Re:What typing ^D does on Unix (2009) by grive on Tuesday September 06, 2016 @02:55PM (#12438349)
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.

Re:What typing ^D does on Unix (2009) by Pete_D on Tuesday September 06, 2016 @03:28PM (#12438631)
There's a lot of unexpected gems in the readline defaults. I recommend people try paging through "bind -p" in bash some time to see what's there.

Personal favorites are C-r to search back in history and C-x C-e to edit the current command line in an external editor.

Re:What typing ^D does on Unix (2009) by Symbiote on Tuesday September 06, 2016 @04:27PM (#12439064)
Emacs users will recognize many of the readline defaults -- unsurprisingly, given both are GNU software.

I use "yank-last-arg" most often, which is M-. by default.

  $ mkdir abcd
  $ cd <M-.>
On Zsh, I have M-, bound to "copy-earlier-word", which makes M-. M-, M-, cycle through the arguments to the previous command.

In reading the manpage for Bash, which doesn't have this function, I've just found "history-search-backward", which searches through history to find commands based on what you've already typed. That will come in useful!

  $ bind '"\er":history-search-backward'
  $ bind <M-r>
(Note that M-r is bound to "revert-line" by default, but I doubt I'll use that.)

These functions are all listed, with explanations, in the Bash and Zsh manpages.

Edit: As I see from another comment, a binding for "history-search-backward" to the Page Up key is in /etc/inputrc on Debian and derivatives.

Re:What typing ^D does on Unix (2009) by wruza on Tuesday September 06, 2016 @03:54PM (#12438816)
It is also very convenient to remap up/down keys to not just list history, but to do completion based on already typed characters:

    if [[ $- == *i* ]]
    then
        bind '"\e[A": history-search-backward'
        bind '"\e[B": history-search-forward'
    fi
(fix: grammar)
Re:What typing ^D does on Unix (2009) by nitrogen on Tuesday September 06, 2016 @04:10PM (#12438946)
Debian and Ubuntu typically have a commented-out mapping for this in /etc/inputrc as pgup/pgdn that I always enable in my ~/.inputrc. Editline supports something similar in .editrc IIRC.
Re:What typing ^D does on Unix (2009) by wruza on Tuesday September 06, 2016 @07:10PM (#12439913)
Funny, I became FreeBSD user because default .cshrc contained it (iirc). I didn't know about shells, readline, etc. back then. Wonder why they do not enable it on up-down by default, cause I see too many linuxoids around bored with up-up-up-enter up-up-up-enter to replay history, not even knowing that completion exists (along with at least ^K ^U ^C).

What's the point to type a half-command and then replace input line with one from history if I press up? That somewhat resembles ugly cmd.exe, which every windows user imagines when someone says 'cli'.

Re:What typing ^D does on Unix (2009) by Sharlin on Tuesday September 06, 2016 @04:41PM (#12439137)
Weird, I'd have thought C-r is the one readline command everybody knows even if they know nothing else abour readline. Almost cannot imagine using command line without it. (Though there's also the "like tab-complete but from history" that I never really learned to use.)
Re:What typing ^D does on Unix (2009) by grive on Tuesday September 06, 2016 @05:13PM (#12439331)
Ah! yes, at this point C-r is so entrenched in my habit, I didnt even realize it might be new to some.

This is the shortcut to first learn when starting living in the command line.

Re:What typing ^D does on Unix (2009) by pixelbeat on Wednesday September 07, 2016 @05:36AM (#12441910)
Yes some of these useful functions should be bound by default IMHO. Here are my settings to bind ctrl-{left,right} and {up,down} to more useful defaults. I.E. jump as the shell tokenizes the line, and search history for what's already typed respectively
Re:What typing ^D does on Unix (2009) by mwpmaybe on Tuesday September 06, 2016 @06:32PM (#12439751)
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.
Re:What typing ^D does on Unix (2009) by StavrosK on Tuesday September 06, 2016 @06:53PM (#12439845)
I'm amazed by how many people still run bash!
Re:What typing ^D does on Unix (2009) by sigzero on Wednesday September 07, 2016 @10:10AM (#12443495)
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) by mwpmaybe on Tuesday September 06, 2016 @07:21PM (#12439966)
¯\_(ツ)_/¯
Re:What typing ^D does on Unix (2009) by grive on Tuesday September 06, 2016 @05:20PM (#12439377)
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) by Pete_D on Tuesday September 06, 2016 @06:55PM (#12439855)
For gdb TUI, you can also use the 'focus cmd' and 'focus src' commands to choose which window gets to handle up/down. I usually keep the command window focused out of habit because the source window intercepts too many keys for my liking.

Nice link - reminds me to try to use the history stuff like ! and ^ more.

Re:What typing ^D does on Unix (2009) by smhenderson on Tuesday September 06, 2016 @03:25PM (#12438613)
I also find Ctrl-W for backspacing a word at a time useful and also Ctrl-A/E for jumping to the beginning and end of the current line.

Ctrl-L to clear the screen except the current line is also somewhat useful if you're at the bottom of the terminal screen and editing a long command line.

Somewhat less useful but neat is Alt-U which will cause the current word under the cursor to become all upper case and Alt-C which is similar but changes the first letter to upper case and the rest of the word to lower case.

Re:What typing ^D does on Unix (2009) by harry8 on Tuesday September 06, 2016 @02:17PM (#12438045)
^Y will paste the cleared buffer back again
Re:What typing ^D does on Unix (2009) by SilasX on Tuesday September 06, 2016 @02:21PM (#12438076)
So ^U will let a partial password linger in memory longer than it needs to if you use it as suggested by the GP?
Re:What typing ^D does on Unix (2009) by klodolph on Tuesday September 06, 2016 @03:14PM (#12438497)
To elaborate on yebyen's answer: these shortcuts can be handled in different layers of your stack. By default, ^U will be handled by your terminal emulator, and it will only delete the buffer, it won't remember what you've deleted. However, programs can ask the terminal emulator to pass ^U through to them so they can handle it themselves. This happens if you use libeditline (or libreadline), and these libraries implement a per-application buffer.

You can test this yourself. Type some text, then ^U, then ^Y. This works because your shell uses libreadline or libeditline. Try this again in a "dumb" program like cat, or a shell without line editing like /bin/dash. ^U works, but ^Y does nothing (well, it lets you type ^Y in as much as you want).

Re:What typing ^D does on Unix (2009) by JdeBP on Wednesday September 07, 2016 @04:35AM (#12441671)
Actually, NAK in canonical mode is handled by the line discipline in the pseudo terminal device rather than by the emulator.
Re:What typing ^D does on Unix (2009) by yebyen on Tuesday September 06, 2016 @02:29PM (#12438152)
No, I don't think so. Not unless you are accustomed to typing your password directly into the terminal prompt. Kill buffers don't pass from one application to another and they don't all behave the same in every context, either.

(For example, if I type some stuff and then ^U to kill the password buffer at an SSH password prompt, typing ^Y after that seems to put the whole process in the background. Not sure what that's intended to do, but subsequent ^Y presses don't retrieve the password into the shell prompt...)

Re:What typing ^D does on Unix (2009) by JdeBP on Wednesday September 07, 2016 @04:37AM (#12441680)
In canonical mode, EM is the usual "delayed suspend" special character.
Re:What typing ^D does on Unix (2009) by breadbox on Tuesday September 06, 2016 @02:38PM (#12438236)
Actually, this is a feature of libreadline (in its default configuration). ^Y mimics the yank command from emacs. At an actual terminal input (like you can get by running `cat` with no arguments), ^Y will just echo back a literal ^Y (assuming it too is in its default configuration).
Re:What typing ^D does on Unix (2009) by y04nn on Tuesday September 06, 2016 @04:41PM (#12439139)
Something I use extensively in terminals is ^L and ^M. ^L clear the screen and ^M for a line return.
Re:What typing ^D does on Unix (2009) by saunders91 on Tuesday September 06, 2016 @04:52PM (#12439214)
May I ask why you find more convenient to press ^M for a line return instead of the line return key?
Re:What typing ^D does on Unix (2009) by Lio on Wednesday September 07, 2016 @03:46AM (#12441505)
As someone else who also uses ^M for line return here's my reason.

I have the Caps key mapped to control, so ^M is 2 small finger movements as opposed to reaching for the return key which means either moving my (weak in my case) right wrist or moving my whole right forearm. It's a small movement to the return key but I find eliminating it really helps to reduce strain related pain when typing.

I also use ^H for backspace and ^I for tab for similar reasons. This also keeps my fingers on the home row.

Re:What typing ^D does on Unix (2009) by philsnow on Tuesday September 06, 2016 @04:56PM (#12439235)
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'.
Re:What typing ^D does on Unix (2009) by knorker on Tuesday September 06, 2016 @08:58PM (#12440334)
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) by ilanco on Tuesday September 06, 2016 @03:03PM (#12438417)
^U is actually very convenient for clearing the current line when using the default mysql client. Still sometimes find myself at the command prompt after ^C because I'm used to psql.
Re:What typing ^D does on Unix (2009) by joboyx on Wednesday September 07, 2016 @10:54AM (#12443885)
Is ^U same as ALT+Backspace? I use this for deleting passwords. But only works for specific shell/ssh/OS.