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…
Ask HN: Best Unix Tricks?
31–40 of 107 posts
Re: Ask HN: Best Unix Tricks?
#32It'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…
Re: Ask HN: Best Unix Tricks?
#33My 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
Re: Ask HN: Best Unix Tricks?
#34ctrl + r Starts a search through your history file.
Re: Ask HN: Best Unix Tricks?
#35 tar cf - * | (cd ; tar xf - )Re: Ask HN: Best Unix Tricks?
#36cd - (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.
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?
#37On 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…
# 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 handlerRe: Ask HN: Best Unix Tricks?
#38 cd ...
to move up two directories instead of having to cd ../..
Want to move up 4 directories? cd .....
Pretty useful, imo. Check it outRe: Ask HN: Best Unix Tricks?
#39cd - (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.
Re: Ask HN: Best Unix Tricks?
#40On 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 /Applications/FooBar.app