4 ms·
> I don't use !! Not even "sudo !!" ? You can see the command you just typed in the line above, and you just forgot to add sudo to it.
by executesorder66 10y ago
> I don't use !!
Not even "sudo !!" ?
You can see the command you just typed in the line above, and you just forgot to add sudo to it.
- kbenson 10y agoNope. It's easier to not have to make a decision about when to use !! or not, so I just don't. Up, Ctrl-a, "sudo ", Enter. 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.
- stinos 10y agoper your own recommendations: "sudo ", alt-. would be one less keystroke
- devnonymous 10y agoA lot of times it is also about muscle memory. For example although I also use alt+. a lot (although not as often as ctrl+alt+.), for adding sudo my brain reverts to up, ctrl+a, sudo simply because I was doing those long before I learnt about Alt+.
- gmazza 10y agoAtl-. will cycle through the n-th argument, which is not the same as repeating entire last command with all arguments as up-arrow or !! do: $ yum install bash-completion Error: This command has to be run under the root user. $ sudo <Alt-.> $ sudo bash-completion
- stinos 10y agogood point, so not equivalent after all
- kbenson 10y agoyes, but it's not equivalent, as Alt-. only repeats the last argument. For 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).
- barrkel 10y agoM-. takes the last argument by default, but it can grab other arguments by using numeric arguments (M-1, M-2, etc.) that usually has the effect of repeating the next command. Unlike Emacs, M-1 etc. can't be typed as C-u 1 etc.
- berntb 10y agoI would never get the habit of using !! with sudo. I want to read what I do, before doing root commands... (Alt-. is possible, I guess. Maybe.) But I'm an epic coward that even looks both to the left and the right before crossing a street. :-)
- p4bl0 10y agoIn addition to never use `sudo !!`, on systems that I use, the sudo is aliased to the following shell script: #!/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.
- buserror 10y agocontrol-p, control-a, 'sudo ' return. 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).
- _asummers 10y agoDon't forget about C-e for end of line and C-d for delete character forward. C-f and C-b make more sense to learn if you have regularly use their whole word variants Meta-f and Metals (alt f/b). Congrats, you know the emacs movement keys.