Not even "sudo !!" ?
You can see the command you just typed in the line above, and you just forgot to add sudo to it.
Not even "sudo !!" ?
You can see the command you just typed in the line above, and you just forgot to add sudo to it.
Another way of putting it is that I'll gladly press another 2-3 keys if it prevents a class or errors and also reduces the number of special bash instructions I have to keep in memory. !! isn't even in my repertoire, but I don't feel its loss.
$ yum install bash-completion
Error: This command has to be run under the root user.
$ sudo <Alt-.>
$ sudo bash-completionFor example, say you want to run "chown root:root foo". Alt-. gets you "foo", not the entire command, and "sudo foo" isn't useful,and in some cases could do something else entirely. For example, with the command "service foo restart", you would end up with "sudo restart" (which while it doesn't execute right away, is exactly what I'm guarding against).
Unlike Emacs, M-1 etc. can't be typed as C-u 1 etc.
But I'm an epic coward that even looks both to the left and the right before crossing a street. :-)
#!/bin/bash
echo -n "Are you SURE you dumbass? [N/y] " >/dev/stderr
read -n 1
if [ "$REPLY" = "y" ]; then
echo >/dev/stderr
exec /usr/bin/sudo "$@"
else
exec echo -e "\n:-)" >/dev/stderr
fi
That way even if I already typed my password, I systematically get asked if I'm sure I want to execute the command.I think I'm pretty proficient as a basher, but I also never use the bang, nor do I use the 'history' bit. Didn't know about alt-. tho, that's handy.
I could toss 'control-k' for 'delete to end of line' that hasn't been mentioned. And of course control-P/N for previous/next commands (or arrows obviously).