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
Ask HN: Best Unix Tricks?
81–90 of 107 posts
Re: Ask HN: Best Unix Tricks?
#82cd - (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?
#83 echo '2^16' | bc
65536
'bc' is a complete calculator language interpreter that also functions quite nicely as a simple calculator. If you need to do any heavy lifting check out:
http://en.wikipedia.org/wiki/Bc_programming_languageRe: Ask HN: Best Unix Tricks?
#84cd - (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?
#85On 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 -a 'TextEdit' foobar.txt
open -a 'TextMate' foobar.txtRe: Ask HN: Best Unix Tricks?
#86 cp /home/foo/abc.cpp{,-old}
equivalent to cp /home/foo/abc.cpp /home/foo/abc.cpp-oldRe: Ask HN: Best Unix Tricks?
#87ctrl + r Starts a search through your history file.
Re: Ask HN: Best Unix Tricks?
#88cd - (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 find myself using the first two on an almost hourly basis.
Re: Ask HN: Best Unix Tricks?
#89ctrl + r Starts a search through your history file.
Map and to do the same in .zsh: # search history on key instead of paging previous commands: bindkey "\e[A" history-search-backward bindkey "\e[B" history-search-forward
"\e[A": history-search-backward
"\e[B": history-search-forwardRe: Ask HN: Best Unix Tricks?
#90ctrl + r Starts a search through your history file.