5 ms·
Damn Useful: When You Forget to type Sudo
- yan 18y agoYou can also get at the arguments of the previous command line with !!:n, where n is the position of the argument. i.e. 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 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. i.e. host:test user$ cat five host:test user$ touch [Esc, .]
- paulgb 18y agoIf anyone is interested in more of these tricks, this document was on HN a while back: http://www.scribd.com/full/2933314?access_key=key-2lwqsfr2e5s00wi1ztjf http://www.scribd.com/full/2933314?access_key=key-2lwqsfr2e5...
- deleted 18y ago[deleted]
- kqr2 18y agoDirect link to pdf on author's web site: http://www.deer-run.com/~hal/UnixCommandLineKungFu.pdf http://www.deer-run.com/~hal/UnixCommandLineKungFu.pdf
- paulgb 18y agoThanks, that was actually the link I wanted to post. When I copied it I realized it was google's big messy click-through URL, so I went for the next result instead.
- randomwalker 18y agoSounds 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? http://www.ukuug.org/events/linux2003/papers/bash_tips/ http://www.ukuug.org/events/linux2003/papers/bash_tips/
- r00k 18y agoI'm "the kid." I intentionally restrained myself to one tip. See http://codeulate.com/?p=21 http://codeulate.com/?p=21 for the reasoning.
- randomwalker 18y agoThat makes total sense for your blog -- getting one tip a day in your RSS reader is way better for learning them than looking at them all at once. However, I don't think it makes sense to post it on HN. If all the posts on the front page were little snippets, the conversation would quickly degenerate.
- r00k 18y agoI think useful content is useful regardless of length. Also, TONS of crap gets submitted to HN. You're seeing this because it was voted to the front page. I don't think I'm affecting the quality of conversation negatively.
- deleted 18y ago[deleted]
- Splines 18y agoStop reminding me that I'm on Windows
- gojomo 18y agoGet cygwin.
- Shamiq 18y agoI didn't really like cygwin when on windows. For some reason, whenever I would hit delete, instead of going backwards and erasing the previous character, it just spaced me forwards. This meant I had to count the number of times I hit backspace then start typing whatever it was I needed in the middle of the next line, surrounded by whitespace. I gave up and switched to Ubuntu.
- nuclear_eclipse 18y agoGet CoLinux [ http://www.colinux.org/ http://www.colinux.org/ ] Edit: even better resource: http://colinux.wikia.com/wiki/Main_Page http://colinux.wikia.com/wiki/Main_Page
- bprater 18y agoDual-boot, my friend!
- apu 18y agoLots of bash tips, organized like bash.org: http://news.ycombinator.com/item?id=142045 http://news.ycombinator.com/item?id=142045
- kqr2 18y agoAlso: http://www.catonmat.net/blog/the-definitive-guide-to-bash-command-line-history/ http://www.catonmat.net/blog/the-definitive-guide-to-bash-co...
- wooby 18y agoBig fan of this: http://developer.apple.com/documentation/OpenSource/Conceptual/ShellScripting/ShellScripting.pdf http://developer.apple.com/documentation/OpenSource/Conceptu...
- tlb 18y agoThat's not something you want to optimize. 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.
- nihilocrat 18y agoImagine 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. 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.
- Dobbs 18y agoThe 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: ^[ k I sudo 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. Slightly more complex but it is reflex from all of the other programs I use.
- kaens 18y agoIf this is new to anyone here, I strongly recommend reading the BASH man page. There's a whole lot of time saving features there.