Hacker News new | ask | show | jobs
by demosito666 1641 days ago
I never understood the utility of history substitution (I think this is what it's called). Why not just ctrl-r to see the actual command? Also, `sudo !!` thingy that is (was?) persistent in the internets for some reason, is probably the dumbest thing out there.
4 comments

`sudo !!` is perfectly alright. It references the very last command, which in all likelihood is right there on your screen, typed by you a few seconds ago, and you're aware of the context.

$!(some number) instead is quite insane and much more likely to have unwanted effects due to (potential) lack of context.

Don't conflate the two.

I never used !! and similar. However my CLI is set to keep the cursor at the front when pressing <Up> to go through history (for easy prefix searching) so I can just use `<Up>sudo ` to get the same result and I like seeing the full command before I run it.
“alias ffs=sudo !!” Is cute though.
`sudo !!` is just very useful, just as most other things you can do with history substitution. Ctrl-R has its own usefulness but it only does a fraction of what history substitution can do.
I like fish shell's approach: [Alt]+[E] prepends the command with `sudo`.

So you hit arrow up to bring up the last command, then [Alt]+[E] to sudo-ify it.