One tip or trick per answer.

My favorite is

open .

Opens the folder you're currently browsing in Finder. You can also pass URLs, images, documents or else to open.

If you specify a program name with -a you can pass the URL, image, document or folder to that program instead, e.g. open -a Preview image.png, overriding the default program set for the filetype.

Please don't post duplicates. Search in the question like this: inquestion:this ls -l

Mac OS X specific answers only.

  • 5
    There is a similar thread on Server Fault as well: serverfault.com/questions/7346/…
    – Chealion
    Oct 7, 2009 at 23:07
  • 5
    You can use open for everything: URLs, images, documents. I use it everyday.
    – olt
    Jul 6, 2010 at 14:48
  • 5
    As an extension to that: open -a Mail filetosend.ext Creates a new Email with the file attached.
    – Skade
    Jul 6, 2010 at 16:11
  • 1
    @Nick Bedford: It's very useful. For example, I use the command line to scp a bunch of files down from the server. Then, I use "open ." to open the current folder up in the finder, where I can easily right-click on a file and say "open in excel".
    – Michael H.
    Jul 12, 2010 at 18:44
  • 1
    @Nick Bedford: If you have the folder open in Terminal, open . opens it Finder. It's useful if you want to do something graphical.
    – ShreevatsaR
    Jul 26, 2010 at 4:40

133 Answers 133


Hit and hold esc a few seconds to get a list of every possible terminal command on your system, including built-ins, programs on your path, and aliases.

Or, as Martijn pointed out:

Just use instead, you don't need to hold it for a few seconds even. will also complete partially typed commands for you, as well as filenames and command-specific arguments.

A prompt asking if you really want to display all command possibilities will appear. Just answer y to get the command list.

  • 5
    Just use <kbd>TAB</kdb> instead, you don't need to hold it for a few seconds even. <kbd>TAB</kdb> will also complete partially typed commands for you, as well as filenames and command-specific arguments.
    – Martijn Pieters
    Jul 26, 2010 at 8:50
  • 2
    If you use Zsh the TAB completion enhancements will rock your world. Try zsh and .oh-my-zsh.
    – ocodo
    Jan 29, 2011 at 8:46

bcat is a convenient pipe between my always-open terminal (xterm under XQuartz) and my always-open browser.

it sets up a streaming HTTP server for just one process so things like

tar czvf - . | tee bcat

will just stream until the command exits. Man pages need a bit of cleanup:

man bash | col -b | bcat

or just

export MANPAGER='col -b | bcat'
man bash

Auto-complete a command as an argument. for example start to type:

which pyt (now press ++1)

it will complete to

which python

++1 works like tab completion except that it auto-completes using command names instead of file names.

  • Looks nice.. Is this supposed to work on Snow Leopard too? It does not work for me..
    – reg
    Sep 12, 2010 at 18:58

This is my absolute favorite. Sharing screen captures via the internet is a hassle. I wrote this to make sharing screenshots across chat a one step process using DropBox. (I have subsequently come across apps and utilities that do this, but I think this is perfect, at least for me.)

It starts the interactive screenshot utility (same as ++4), saves it your Dropbox's public folder, copies the URL to your clipboard and opens it in your browser.

I run it via LaunchBar, but you could run it from the shell or bind it to a keyboard shortcut to make it as easy as ++5.

You could add something random to the filename if you are worried about privacy.

I used to have it scp the screenshot file to my webserver before I switched to Dropbox. You could send the file wherever it would be useful to you. You could even put it in your ~/Sites directory to use it on your local network.

If you want sign up for dropbox, you can use my referral link which will give us both bonus storage. =)


# Integrates Mac OS X's screenshot utility with DropBox for easy sharing.

# - Starts the interactive take-screenshot function, saves it to your public
# Dropbox (if you didn't cancel it) where it will be uploaded automatically.
# Copies the public URL to your clipboard and opens your browser to it.

## Config
dropbox_id="112358132134"  ## this is fibonacci's dropbox id

## Derivative Variables
filename=$(date '+%F__%H-%M-%S.png')

## start interactive screen capture
screencapture -i "$save_to"

## if the screenshot actually saved to a file (user didn't cancel by pressing escape)
if [[ -e "$save_to" ]]; then
    ## echo some output in case you run this in a shell
    echo "Saved screenshot to:" "$save_to"

    ## copy url to the clipboard
    echo "$url" | pbcopy

    ## wait for Dropbox to upload your screenshot, then open in your browser
    sleep $upload_delay_in_second
    ## The `-g` flag means it won't bring your browser to the foreground, which 
    ## feels less like getting interrupted.
    open -g "$url"
  • This is nice if you want to use DropBox for storage, but almost seems like overkill when considering that Imgur, TinyGrab, and Skitch all have OSX utils.
    – brianicus
    Jul 25, 2010 at 19:57
  • That's true, unless you consider those sort of hosts to be temporary and volatile. I don't really know if that's the case anymore, but I like having control of my files.
    – user1644
    Jul 29, 2010 at 5:19
  • Imgur is a much better choice than DropBox. Try this script. figbug.com/?page_id=29
    – ocodo
    Jan 29, 2011 at 9:02
  • I still like DropBox, but good to know.
    – user1644
    Jan 31, 2011 at 16:02
  • This is already a DB feature. Jan 10, 2014 at 12:10

Use ctrl+R to active reverse history search. Then start typing a command you've already typed and all matching commands will start presenting to you.

To navigate in the reverse history search simply:

  • continue typing to narrow down search
  • ctrl+R: move to the next result
  • : go back to the previous result
  • ctrl+C: cancel your search


apouche:bin>  echo 'type CTRL+R to start reverse search'
(reverse-i-search)`fin': find . -exec grep "MainMenu.nib" {} \;

See also the accepted answer to "How can I search the bash history and rerun a command?" on Super User.

  • really handy bash command Aug 26, 2011 at 8:56

The more I use it the more addicted to it I am.


Along with

screen -ls
screen -r [session]

Very useful for having several screens open on an SSH connection. It saves tons of time especially when you don't have to restart your tail everytime you want to check another log file.

  • 2
    Sadly it's not part of OS X by default but consider tmux. It's basically a better BSD equivalent of GNU screen.
    – Peter Cooper
    Jul 6, 2010 at 14:01
  • Strangely on my 10.6.4 OSX, screen exists but tmux does not... I guess I got it via macports - tmux must be a separate install too.
    – Chris Kimpton
    Jul 25, 2010 at 17:42

diskutil is a very powerful command-line tool for working with disks and disk images. It's gotten me out of some binds. It's not too hard to use.


I’m not sure; this might work in any decent terminal application, not only in OS X’s. However:

Using Terminal.app it is possible to put status information to the actual title bar and not just to the prompt.

In order to do that, you need to change the PS1 variable in bash to the following model:


Where TITLE and PROMPT must be substituted to the actual commands which provide the status information. For example, \w lists the current full path; \W the directory name. You can even execute a command by putting it in backticks. (So you could even put the output of arbitrary commands to the title – or to the prompt.)

Git users (with git’s bash completion installed) might find the following useful. Add this to your .bashrc

PS1='\[\033]0;`__git_ps1` \w\007\]\h:\W \u\$ '

and the title bar of Terminal.app will show the current git branch (and whether it’s clean or not) followed by the current full path. This gives useful information about where you are only when you need it and does not make the actual prompt overly long.

In case you don’t use git very much and only care about the path in the title bar:

PS1='\[\033]0;\w\007\]\h:\W \u\$ '
  • What's git's bash completion?
    – Yar
    Apr 14, 2010 at 23:47
  • I'd recommend zsh + .oh-my-zsh (find it on github) has great git completion (and for many other commands too.) - Also has a bunch of prompt themes specifically tailored to show git status in a git folder.
    – ocodo
    Jan 29, 2011 at 8:54
  • 2
    As of Mac OS X Lion 10.7, Terminal also supports setting the tab title separately from the window title. "0" sets both. Use "1" to set the tab title, "2" to set the window title. ("1" technically means "icon title", but Terminal uses it for the tab title, since it doesn't have icon titles in the same sense that xterm and X11 do.)
    – Chris Page
    Aug 19, 2011 at 11:42

I'm going to have to say watching Star Wars from the command line is the best:

telnet towel.blinkenlights.nl

If you say that isn't a command, which it isn't really, just a trick, then I like this:

defaults write com.apple.dashboard devmode YES

  • Ahh, so opening telnet is just telnet... Thanks!
    – gary
    Jul 31, 2011 at 12:37
  • No problem, I guess... :)
    – Odinulf
    Aug 1, 2011 at 13:49
  • this is so epic Nov 11, 2011 at 21:41

Print almost any document as a PDF, as long as it has a correctly defined MIME type in OS/X

 cupsfilter $filename > output

Here's a shell function to get the path of the front Finder window. Can be handy. (I started doing this instead of dragging a folder into the Terminal window.)

function fp { osascript -e 'tell application "Finder"'\
 -e "if (${1-1} <= (count Finder windows)) then"\
 -e "get POSIX path of (target of window ${1-1} as alias)"\
 -e 'else' -e 'get POSIX path of (desktop as alias)'\
 -e 'end if' -e 'end tell'; };\

## alias to copy it to the clipboard
alias cfp='fp | pbcopy'

(This has been in my zshrc a while, but I don't know where I got it / parts of it, otherwise I'd cite credit.)


Easily burn an ISO from commmand line (with verify burn at the end):

hdiutil burn /path/to/iso

Without verifying the burn:

hdiutil burn -noverifyburn /path/to/iso

Get a list of airport SSID

/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -s

the airport utility has a lot more options to manage the airport configuration. Run without the -s to get a list.

  • 1
    if you tire of long pathnames like this, try locate airport - you could run it with $(locate airport | grep 'Priv')
    – ocodo
    Jan 29, 2011 at 9:15

the most interesting pschotherapist you will ever talk to:

  • Run emacs
  • Press +esc+X
  • type doctor and press enter
  • have fun :D
  • 11
    That's just part of emacs, it's not OS X specific
    – Josh
    Feb 24, 2010 at 18:10
  • wow, this is really fun Jan 3, 2011 at 2:15
  • It's hilarious! I love it!
    – daviesgeek
    Oct 20, 2011 at 3:55

alias to open preview from command line

alias preview='groff -Tps > /tmp/tmp.ps && open -a Preview /tmp/tmp.ps'

So you can do :

echo "toto" | preview
cat /tmp/test.log | preview
cheat git | preview
  • Well, if it respected line-breaks it might even be useful ;) -- Try cupsfilter instead to convert to PDF, it also skips the unnecessary PS-PDF conversion.
    – ocodo
    Jan 29, 2011 at 9:21

Putting a couple of these together, we can get manual pages in a browser with proper markup:

bman () {
    gunzip < `man -w $@` | groff -Thtml -man | bcat

None of these are exactly OSX specific, but here's some stuff from my .bash_profile that I find useful:

Colored Prompt:

PS1="\[\e[0;31m\][\[\e[1;31m\]\u\[\e[0;34m\]@\h \[\e[32m\]\w\[\e[0;31m]\]\$\[\e[0m\] ";

example http://grab.by/grabs/c2c7cdff8e49dd764d326620df762665.png

SSH tab completion of hosts that exist in ~/.ssh/config: (found on MacOSXHints)

complete -o default -o nospace -W "$(/usr/bin/env ruby -ne 'puts $_.split(/[,\s]+/)[1..-1].reject{|host| host.match(/\*|\?/)} if $_.match(/^\s*Host\s+/);' < $HOME/.ssh/config)" scp sftp ssh

Highlighted grep:

alias grep="grep --color=auto"

highlighted grep http://grab.by/grabs/dd26dd993c74f8dd076e2f911a8e4ec6.png

Automagically dump your public ssh key to a host for future passwordless auth: (can probably easily tweaked to add said host to ~/.ssh/config)

ssh-setup() { cat ~/.ssh/id_rsa.pub | ssh $1 'cat - >> ~/.ssh/authorized_keys'; }

More OSX specific stuff that I've setup forces the machine to take a picture with the built-in iSight every time the machine's lid is open and dumps that image in a directory.

Create a directory somewhere to hold all your images. Dump this into ~/.wakeup:

date=$(date +%y%m%d_%H_%M_%S).jpg;
/PATH/TO/isightcapture -w 640 -h 480 -n 3 -d -t jpg /PATH/TO/PICTURE/DUMP/$date > /dev/null
unset date

I've been capping a frame every time my MacBook wakes up for the past 3 1/2 years now, it's interesting to see everything compiled into a long video at a high framerate.

  • Your images are broken.
    – daviesgeek
    Sep 23, 2011 at 16:44

Not installed by default, but MacPorts is great for adding more command line programs. After downloading and installing you can use the port command to find and install more programs, plus much more.

port search convert video
port install ffmpeg
  • It's worth noting that you will need to install XCode before you can install MacPorts.
    – ocodo
    Sep 4, 2011 at 23:13
  • 2
    And homebrew is much better mxcl.github.com/homebrew
    – Steve Ross
    Jun 25, 2012 at 13:32

My favorite alias:

alias redo='sudo \!-1'

When you forget to use 'sudo', just do 'redo' to rerun the last command using sudo.

  • 10
    You can also use !! to mean the last command, so you can do: sudo !!
    – Joe Shaw
    Jul 26, 2010 at 13:54
  • if you feel the need to use an alias with more chars than the actual command, consider rewiring your temporal neocortex.
    – ocodo
    Sep 4, 2011 at 23:18

Use !$ to repeat the last parameter in the last command you entered, for example:

~$ mkdir test-dir
~$ cd !$
cd test-dir

!$ is actually short for !!$ which means "from the most recent command, pull the last parameter"

See the "HISTORY EXPANSION" section of the bash man page for more.

  • 3
    Similarly, there is !^ for the first command, which I happen to use often.
    – Pascal
    Aug 9, 2010 at 9:58
  • !! also works fine
    – v2r
    Mar 4, 2012 at 4:25
afplay ~/path/to/file.mp3

Let's you play songs from the commandline. You can also append [space]& and let it run in the background. :)

  • If you were in the tracker/module scene back in the day, you can try xmp (compiled Rudix package here). Then just xmp ~/path/to/file.mod.
    – user36018
    Jan 10, 2014 at 16:49

Not a huge feature, but I noticed it wasn't here.

+ mouse drag on Terminal text let's you make a rectangular selection.

  • Clarification: It's the "Option" key, not the "Alt" key. It also happens to have an "Alt" label to help people more familiar with Windows, or someone using Windows with an Apple keyboard, including someone using Windows running on a Mac via Bootcamp or a virtualization program like VMware.
    – Chris Page
    Aug 28, 2011 at 8:17

The OSX installer app has a command line interface too.

sudo installer -pkg /Volumes/Growl-1.2.1/Growl.pkg -target LocalSystem

Is a one line install command for Growl, GrowlNotify is an extra on the same install disk image.

You can find the domains supported by a package file via

installer -pkg  /Volumes/Growl-1.2.1/Growl.pkg -dominfo
xattr -h

allows you to view file attributes. The most handy use for this command is to remove the internet download warning from the finder:

cd /the/directory/where/you/downloaded/all/your/files

xattr -rd com.apple.quarantine .
history|awk '{print $2}'|awk 'BEGIN {FS="|"} {print $1}'|sort|uniq -c|sort -r

Gives you a list of some of your most recent commands, numbered by how often you use them.


Create a new directory and enter it:

md() { mkdir -p "$@" && cd "$@"; }

For more, see my dotfiles repository on GitHub, and/or view my .osx file for OS X-specific preferences and settings.


Repeat the previous command with a substring replacement:




You entered:

git clonr https://unbelievablylongurl.org/projectdirectory/evenmoreprojects/project.git

Use this:


And your command will be re-run with the replaced substring:

git clone http://unbelievablylongurl.org/projectdirectory/evenmoreprojects/project.git

You can transfer a working directory from one Terminal window to another with these two commands added to your .bash_profile file:

alias cwd='pwd | pbcopy'
alias gowd='cd "`pbpaste`"'

cwd copies your working directory from one window, and gowd opens that directory in another window.

  • So that’s how to make it work. I was always despairing on the gowd part …
    – Konrad Rudolph
    Jul 25, 2010 at 17:33

In my bash profile I have these aliases:

# Alias for "." shows current directory
alias -- .='pwd'

# Alias for ".." goes to parent directory
alias -- ..="cd .."
alias -- ...="cd .. ; cd .."
alias -- ....="cd .. ; cd .. ; cd .." 
  • 1
    Yeah, me too, working on a shell that doesn't have '..' is strange. :) (FWIW, You could also use alias '..'='cd ../..')
    – Pascal
    Aug 9, 2010 at 9:56

Use Apple’s ASCIIMoviePlayer to play QuickTime movies in the Terminal:

(There are also two great adaptations out there that allow using ANSI colour output).

On a more serious note: CoreImageTool (3rd party; just google for it) is a great way of using CoreImage filters from the command line.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .