Live data from Hacker News

Ask HN: Best Unix Tricks?

news.ycombinator.com

81–90 of 107 posts

Re: Ask HN: Best Unix Tricks?

#81

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

You can also do this with "cd -"

Re: Ask HN: Best Unix Tricks?

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

What is the difference with :w! ?

Re: Ask HN: Best Unix Tricks?

#83
One of the little things that it took me a while to find out about:

  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_language

Re: Ask HN: Best Unix Tricks?

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

mkdir -p (create a chain of directories in one call)

Re: Ask HN: Best Unix Tricks?

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

You can also specify the app to open using the -a flag and specifying the full name of the app (with correct spacing and capitalization), e.g.:

    open -a 'TextEdit' foobar.txt
    open -a 'TextMate' foobar.txt

Re: Ask HN: Best Unix Tricks?

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

Excellent list. I use all of those except the last, which is new to me and extremely useful--so, thanks! It's now aliased.

I find myself using the first two on an almost hourly basis.

Re: Ask HN: Best Unix Tricks?

#89
post #45
post #5

ctrl + 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

Or in bash, using .inputrc (readline):

  "\e[A": history-search-backward
  "\e[B": history-search-forward

Re: Ask HN: Best Unix Tricks?

#90
post #5

ctrl + r Starts a search through your history file.

This works because you're in emacs mode, which gives you a bunch of other tasty shortcuts (http://www.scribd.com/doc/985254/Bash-Emacs-Editing-Mode-rea...) as well. There is an equivalent vi mode as well ("set -o vi").
Post reply on HN