News for hackers. Stuff that matters.
Re:Devops/Sysadmin Cheatsheet by cwh on Friday January 11, 2013 @11:53AM (#5043500)
I would warn anyone that read this to understand what each command does before actually running anything on a machine.

Things like "sudo !!" are INCREDIBLY dangerous, and I would never put that on a cheat sheet.

Re:Devops/Sysadmin Cheatsheet by mhurron on Friday January 11, 2013 @12:04PM (#5043572)
Anyone running commands blindly without knowing what they do deserves what they get. That goes for potentially dangerous commands or not.

Or put in a slightly nicer way - Blindly running commands is going to turn into a learning experience, don't do it on a production machine.

Re:Devops/Sysadmin Cheatsheet by jiggy2011 on Friday January 11, 2013 @12:17PM (#5043666)
I suppose if you type it at any random point it might be. It's useful more when typed something that you forgot to sudo.
Re:Devops/Sysadmin Cheatsheet by darkarmani on Friday January 11, 2013 @01:01PM (#5043973)
If you are running sudo, the long-term payoff is probably higher if you never use sudo !!. The very small chance of a huge disaster is still a lot higher than up arrow. Unless you are on a laggy connection and up arrow delays and you push it twice and end up running the wrong command!

If you have lots of jitter and lag, i suggest using Mosh which I've found to be amazingly awesome when using it on Amtrak's spotty free wifi (3G uplink).

Re:Devops/Sysadmin Cheatsheet by ineedtosleep on Friday January 11, 2013 @01:30PM (#5044158)
I've never had any incidents with `sudo !!`, however, I should point out that zsh (maybe other shells as well) replaces the `!!` with the full command and requires another press of Enter.

    $ rm -rf /root
    rm: cannot remove `root': Permission denied
    $ sudo !!  # Does not run this, but returns the line below.
    $ sudo rm -rf /root  # Then you say, "Wait I dont want to do this."
Re:Devops/Sysadmin Cheatsheet by chc on Friday January 11, 2013 @01:39PM (#5044211)
Interesting. Bash on my OS X box shows the command you're running, but doesn't give you a chance to cancel it. It looks like this:

  $ rm -rf /root
  rm: cannot remove `root': Permission denied
  $ sudo !!
  sudo rm -rf /root
  # /root is now kaput
Re:Devops/Sysadmin Cheatsheet by chc on Friday January 11, 2013 @01:36PM (#5044195)
I think it's meant for when you run a command normally, but then realize you should have sudoed (sudid?) it. Though in that situation, I would still be inclined to do "↑ esc a sudo ". It's not a lot more work, but it is a lot less uncertain.
Re:Devops/Sysadmin Cheatsheet by aidos on Friday January 11, 2013 @04:08PM (#5045030)
Indeed. I find ctrl-p ctrl-a is faster than going to the cursors.
Re:Devops/Sysadmin Cheatsheet by chc on Friday January 11, 2013 @05:05PM (#5045341)
Whoops, thanks. Should have been ctrl-a, but spelling out muscle memory is, like, hard.
Re:Devops/Sysadmin Cheatsheet by sp332 on Friday January 11, 2013 @02:33PM (#5044494)
Shoulda sudone it!
Re:Devops/Sysadmin Cheatsheet by AaronBBrown on Friday January 11, 2013 @02:58PM (#5044634)
I use this one like a dozen times a day.

  user@host$ less /var/log/syslog
  Permission Denied
crap...

  $ sudo !!
  sudo less /var/log/syslog
Woo!
Re:Devops/Sysadmin Cheatsheet by sudara on Saturday January 12, 2013 @07:31AM (#5047617)
This is exactly how I use it. A time saver for mundane "whups" moments.
Re:Devops/Sysadmin Cheatsheet by biturd on Friday January 11, 2013 @03:15PM (#5044721)
why would that be bad? You would get to read your file.
Re:Devops/Sysadmin Cheatsheet by AaronBBrown on Friday January 11, 2013 @08:48PM (#5046138)
It's not bad. It's extremely useful. If someone is so negligent that they run something potentially destructive and then immediately sudo !!, they probably shouldn't be administering systems.
Re:Devops/Sysadmin Cheatsheet by ericcholis on Friday January 11, 2013 @12:00PM (#5043540)
Truthfully, I'm more comfortable using the up arrow and re-running it manually. At least I can inspect what the command was before running it.

Obviously, this doesn't help when using Fabric or scripting, but you shouldn't need "sudo !!" in those scenarios.

Re:Devops/Sysadmin Cheatsheet by CJefferson on Friday January 11, 2013 @12:54PM (#5043925)
So, what's wrong with sudo !! then?
Re:Devops/Sysadmin Cheatsheet by dror on Saturday January 12, 2013 @07:03AM (#5047558)
It's too easy to have a sticky key and type sudo !1 by accident. As a rule, not a good idea to do sudo from history without examining it first. So do up arrow or CTRL-P and the edit the command.
Re:Devops/Sysadmin Cheatsheet by dsr_ on Friday January 11, 2013 @01:26PM (#5044133)
It re-executes your previous command -- this time with root privilege.

If and only if you meant to do that, you're fine.

Re:Devops/Sysadmin Cheatsheet by Firehed on Saturday January 12, 2013 @12:05AM (#5046572)
Why else would you type it in? I can't imagine many people saying "hm, that command I didn't intend to run didn't work. Maybe I should run it as root instead."

Hopefully if you're in a NOPASSWD user/group, you know what root can do if you're careless; if you're not, there's yet another point where you'd have go out of your way to do damage with this shorthand.

Re:Devops/Sysadmin Cheatsheet by dbaupp on Friday January 11, 2013 @06:20PM (#5045622)
The "only if" part is false: it is certainly possibleto be fine having done sudo !! without meaning to do it.