An easy trick (in tcsh) to perform the last command as sudo is:
sudo !!This uses the powerful "History substitution" feature of tcsh. For more history substitution tricks: "man tcsh" and type "/History"
|
|
|
Isn't it annoying when you try to do something, only to find out it requires superuser privs? And you have to retype it with "sudo"? No more!
An easy trick (in tcsh) to perform the last command as sudo is: sudo !!This uses the powerful "History substitution" feature of tcsh. For more history substitution tricks: "man tcsh" and type "/History"
•
[4,632 views]
Hint Options
Tim Toady
This is indeed a useful trick but ...you can just hit the up key [roll back to previous command(s)], jump to the beginning of the line [Emacs keybindings: ctrl+A for beginning, ctrl+E for end, etc], type "sudo " and hit enter. The big timesaver there is the [UP] [ctrl+A] combo: you can scoll back any number of commands, add the sudo prefix, and while you're at it you can make any minor edits to the command too.
That said, this isn't all that different from the original trick. Both of them work out to 5+3 keystrokes ('sudo " plus either [shift 1 1] or [up control A]). The scrolling through history trick I describe makes it easy to see what you're [re]executing, but the exclamation points hack is actually much more subtle than this. I personally haven't really pushed it, but it's possible to use your command history interactively -- such as repeating the last "grep" command, even if it was some time yesterday. The tcsh man page goes over this, but I also recommend taking a look at O'Reilly's Unix Power Tools. It has a big section on the different shells & how they can be leveraged. There's also the csh/tcsh book, but the Power Tools one covers *everything*, so if you get stuck on a Linux machine and have to use Bash you'll be able to look up the trickery there too :-)
naw
control-a is pretty hard to type, especially now that the control key is in the corner. sudo !! is also easier mentally, in that you don't have to carefully hit the up-arrow and make sure the command is the right one. (that you didn't hit it too many times)
more on history
and just because it may not be obvious, you can use the history command; then type !number, where number = the command number in your history output. For example: !59. |
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.22 seconds |
|