Here's another pro tip. Say you wanted to run a command in sudo context but forgot that. Usually you'd hit the up arrow, press ctrl+a, or HOME button, type sudo and hit ENTER.

There is a geekier way to do that. Just type:

$ sudo !!

Bash will expand the two exclamation points to the previous command and it will be run through sudo.

Comments

Jeff Erickson Permalink
May 10, 2014, 16:07

It also leaves sudo + the actual command in your history, so that if you want to rerun it by finding it in history, you don't have to worry about it running another command.

Simon Permalink
May 11, 2014, 11:06

The variant of that command I usually use is to find and edit a file...

> find . -name whatever.txt

> vim `!!`

May 14, 2014, 16:48

Great little tip Peteris. I love sudo. Some tricks I do are to make s an alias of sudo, but only if the user isn't root.

[[ ${EUID:-} -ne 0 ]] && alias s='sudo ' || alias s=' '

Also are you aware of your spam problem in the comments?

May 15, 2014, 11:16

This is a great trick. Thanks for sharing. I'm aware of the spam problem. These spammers have taken over my blog. I don't now how to fight them. Any ideas?

Ingus T Permalink
May 29, 2014, 04:16

One letter can not be considered a defense mechanism. Implement some kind of CAPTCHA.

Alex Vorobyev Permalink
June 10, 2014, 04:40

To fight with spam use databases from http://www.stopforumspam.com

Leave a new comment

(why do I need your e-mail?)

(Your twitter name, if you have one. (I'm @pkrumins, btw.))

Type the word "cloud_420": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.

Advertisements