Live data from Hacker News

Ask HN: Best Unix Tricks?

news.ycombinator.com

61–70 of 107 posts

Re: Ask HN: Best Unix Tricks?

#61
post #24

On OS X pbcopy and pbpaste are useful for working with clipboard data. Copy data from a web-page or whatever, manipulate it on the command-line to get what you want. Putting reasonably large files in the clipboard can be useful too. For example: curl http://news.bbc.co.uk/ | pbcopy # copies a web-page to clipboard Depending on what you are doing it can be very useful: pbpaste | sort | pbcopy # sort the contents of th…

open also takes the -a argument to specify which application to use. It's very handy for things like this:

    alias shop="open -a Adobe\ Photoshop\ CS3"

Re: Ask HN: Best Unix Tricks?

#63
post #12

cd - (Go back to previous working directory) sudo !! (Run the last command as root) :w !sudo tee % (Save a readonly file in VIM) > tmp.file (Empty a file) cmd !$ (Run cmd with previous commands arguments) They are just some of my favorites.

I think :w !sudo dd of=% is better. Can't remember why, though.

Re: Ask HN: Best Unix Tricks?

#65
post #36
post #12

cd - (Go back to previous working directory) sudo !! (Run the last command as root) :w !sudo tee % (Save a readonly file in VIM) > tmp.file (Empty a file) cmd !$ (Run cmd with previous commands arguments) They are just some of my favorites.

That should be cmd !*. !$ would only be the final argument to the previous command, which you can also insert with alt-. (and pressing alt-. again will cycle through final arguments to earlier commands). Adding :p to the end of a history expansion (like !$:p) will cause it not to be executed, but the expanded command line will be echoed and put in your history so you can check edit it.

M-. also takes a numeric argument (M-number or ESC number) to yank the nth word instead of the last.

Re: Ask HN: Best Unix Tricks?

#67
post #49

screen is infinitely useful.

Yes, it is. I recommend remapping the standard C-a to C-z, as C-a acts as "jump to the beginning of line" in couple of shells, Emacs and Emacs clones.

I'm not sure that C-z is a great choice as it's often used for job control. I use C-o myself. I suppose you could always use C-z C-z if you wanted to suspend your current foreground process.

Re: Ask HN: Best Unix Tricks?

#68

Pipes, grep and such come in handy in many applications. For example: ps -e | grep processname will grab the pid of any process so that you can subsequently kill it. sudo !! (run last command as sudo) is great too when you forget to type sudo on a regular basis like me.

will grab the pid of any process so that you can subsequently kill it I like to use: killall processname

And that works just dandy, until that one day you're on a Solaris machine...

Re: Ask HN: Best Unix Tricks?

#69
post #42

nc lets you talk directly to a remote host, and strace allows you to eavesdrop on an arbitrary process' communication with a remote host (or with anything, really). Actually, I rather hope there's something better than strace for the latter. But it works.

Also consider socat ( http://www.dest-unreach.org/socat/ ) aka "netcat++".

Re: Ask HN: Best Unix Tricks?

#70

Pipes, grep and such come in handy in many applications. For example: ps -e | grep processname will grab the pid of any process so that you can subsequently kill it. sudo !! (run last command as sudo) is great too when you forget to type sudo on a regular basis like me.

pkill and pgrep are useful too!
Post reply on HN