Five Cool OS X Terminal Tricks

March 7th, 2010 by Tuomas Rasila

Photo courtesy of Mads Sabroe

We all love Unix shell. I can’t remember when was the last time I had my Mac running without an open Terminal window. Here are couple of tricks you can do with it.

1. “cd -”
After finding this in all of its simplicity I asked many of Linux & OS X hardcore users and none of them knew this existed. “cd -” sends you back to the last directory you where in:

macbookpro:/ tuomas$cd usr/bin/
macbookpro:bin tuomas$ cd -
/
macbookpro:/ tuomas$ cd -
/usr/bin

2. “mkdir -p”
With mkdir you can make a directory, but adding the “-p” argument can make multiple directories in case those do not exist before. For example:

mkdir -p /home/bill/documents/books/computer

3. Update Twitter from shell with cURL

curl -u username:password -d status="Your tweet" http://twitter.com/statuses/update.xml

4. Speak a text file to spoken .aiff file

cat foo.txt |say -o foo

Now try this with Apache log;)

5. “history”
History shows you list of commands you have ran before like this:

526  cat blog-google-api.txt |say -o foo.mp3
527  open .
528  ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
529  history

If you want to run something from your history you can just: !527 and it will run command #527 from the history. In this case: “open .”

Share and Enjoy:
  • del.icio.us
  • Digg
  • Facebook
  • Reddit
  • Twitter

Tags:

2 Responses to “Five Cool OS X Terminal Tricks”

  1. Eero Lemmelä says:

    I’m guessing you’re using bash here.?. “cd” remembers* only the last directory you’ve visited. If you want to remember** a stack of directories take a look at “pushd”, “popd” and “dirs”. They are bash built-in commands, so “man bash”…

    * stored in OLDPWD variable
    ** stored in DIRSTACK array (yes, bash has array variables ;)

  2. Tuomas Rasila says:

    Yep, Bash it is. Only #4 is the only “Mac only” thing.

Leave a Reply