Live data from Hacker News

Ask HN: Best Unix Tricks?

news.ycombinator.com

31–40 of 107 posts

Re: Ask HN: Best Unix Tricks?

#31
post #2

It's a great kill-ur unix tip but you should never fall for it: :(){ :|:& }; Oh, the temptation... if you're thinking of cutting & pasting that into the shell of your machine google for 'bash fork bomb' first, I've left off the final ':' to set it off. Anyway, on a more serious note, after an installation procedure that was a lot of work, if you want to document the whole thing use: history | cut -d ' ' -f 5- To give…

Up-modded. But also wanted to add a spot of thanks for the bash fork bomb tidbit. That was beautiful :)

Re: Ask HN: Best Unix Tricks?

#32
post #2

It's a great kill-ur unix tip but you should never fall for it: :(){ :|:& }; Oh, the temptation... if you're thinking of cutting & pasting that into the shell of your machine google for 'bash fork bomb' first, I've left off the final ':' to set it off. Anyway, on a more serious note, after an installation procedure that was a lot of work, if you want to document the whole thing use: history | cut -d ' ' -f 5- To give…

I usually use ps -auxf for the best output on linux. unfortunately the OSX version of ps doesn't support foresting, so sad.

Re: Ask HN: Best Unix Tricks?

#33

My tip: pushd without an arg pushes the current directory onto the stack, and then switches to what popd would have. Hence, repeated invocations of pushd let you cycle between two directories without thinking. $CDPATH is also amusing: $ mkdir /foo/bar/baz $ cd baz bash: cd: baz: no such file or directory $ export CDPATH="/foo/bar" $ cd baz $ pwd /foo/bar/baz

could you give an example of the pushd thing you mentioned?

Re: Ask HN: Best Unix Tricks?

#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.

Re: Ask HN: Best Unix Tricks?

#37
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…

The equivalent Linux commands are:

    # xclip:
    curl http://example.org | xclip
And instead of "open", you can use:

    xdg-open file.pdf
    xdg-open music.mpe
(or even gnome-open if you're on gnome) will open up the file with their default handler

Re: Ask HN: Best Unix Tricks?

#39
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.

then checkout http://www.commandlinefu.com/commands/browse/sort-by-votes

Re: Ask HN: Best Unix Tricks?

#40
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…

And "open" works on bundles, allowing you to avoid descending into the /Contents/... part.

    open /Applications/FooBar.app
Post reply on HN