TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Damn Useful: When You Forget to type Sudo

25 点作者 r00k超过 16 年前

11 条评论

yan超过 16 年前
You can also get at the arguments of the previous command line with !!:n, where n is the position of the argument.<p>i.e.<p><pre><code> host:test user$ touch one two three four five host:test user$ ls five four one three two host:test user$ cat four host:test user$ echo !!:1 echo four four </code></pre> Also, "Esc, dot" is an awesome bash shortcut. (Press them consecutively, not concurrently). It inserts the last argument of the previous command in place. So if you're doing something to the same file, Esc, . will usually bring up the file name.<p>i.e.<p><pre><code> host:test user$ cat five host:test user$ touch [Esc, .]</code></pre>
评论 #391452 未加载
评论 #391536 未加载
randomwalker超过 16 年前
Sounds like some kid discovering a bash feature, nothing more. May I post a link to a page with a whole lotta nifty bash tricks instead? <a href="http://www.ukuug.org/events/linux2003/papers/bash_tips/" rel="nofollow">http://www.ukuug.org/events/linux2003/papers/bash_tips/</a>
评论 #391620 未加载
tlb超过 16 年前
That's not something you want to optimize.<p>When working on a production box, I've trained myself to type the command without sudo, then actually take my hands off the keyboard and sit on my hands while I ponder what might go wrong with the command. Then I hit ^A sudo space return.
apu超过 16 年前
Lots of bash tips, organized like bash.org: <a href="http://news.ycombinator.com/item?id=142045" rel="nofollow">http://news.ycombinator.com/item?id=142045</a>
nihilocrat超过 16 年前
<i>Imagine an angry father yelling for his son. “Sudo!!” Sudo runs down from his room, sees the command he was supposed to be in front of, and executes it immediately.</i><p>No, no, he's got it all wrong. The son then says "Okay, I'll do it in a minute" and proceeds to go back to playing WoW or whatever he does for fun.
paulgb超过 16 年前
If anyone is interested in more of these tricks, this document was on HN a while back: <a href="http://www.scribd.com/full/2933314?access_key=key-2lwqsfr2e5s00wi1ztjf" rel="nofollow">http://www.scribd.com/full/2933314?access_key=key-2lwqsfr2e5...</a>
评论 #391603 未加载
评论 #391600 未加载
Dobbs超过 16 年前
The way mentioned in the article, might be slightly easier but as I am a vim user and have the vi mode enabled in bash,my command chain for this action is:<p>^[ k I sudo<p>Esc (^[ = Esc) exits to command mode, k goes to the previous command, shift-i moves the cursor to the beginning of the line and sudo is well sudo.<p>Slightly more complex but it is reflex from all of the other programs I use.
wooby超过 16 年前
Big fan of this: <a href="http://developer.apple.com/documentation/OpenSource/Conceptual/ShellScripting/ShellScripting.pdf" rel="nofollow">http://developer.apple.com/documentation/OpenSource/Conceptu...</a>
kqr2超过 16 年前
Also:<p><a href="http://www.catonmat.net/blog/the-definitive-guide-to-bash-command-line-history/" rel="nofollow">http://www.catonmat.net/blog/the-definitive-guide-to-bash-co...</a>
kaens超过 16 年前
If this is new to anyone here, I strongly recommend reading the BASH man page. There's a whole lot of time saving features there.
Splines超过 16 年前
Stop reminding me that I'm on Windows
评论 #391713 未加载
评论 #391544 未加载