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.

locked by stuffe Mar 25 '14 at 22:21

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: help center.

migrated from Dec 26 '10 at 8:40

This question came from our site for computer enthusiasts and power users.

  • 5
    There is a similar thread on Server Fault as well:… – Chealion Oct 7 '09 at 23:07
  • 5
    You can use open for everything: URLs, images, documents. I use it everyday. – olt Jul 6 '10 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 '10 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 '10 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 '10 at 4:40

133 Answers 133

sips -i *

This automagically creates icon previews for all images.

This is better than using the Finder’s “Show icon preview” if you have large files particularly over a server.

drutil does lots of stuff

drutil cdtext

shows you the cdtext info (if any) on the CD currently in the drive

drutil info

shows you the capability of your optical drive(s)

drutil eject

guess what that does

Plus lots more. 'man drutil' to see everything

I often use +K to have my Terminal screen cleared instead of UNIX Command clear.

The difference is clear hides the previous commands from our sight, but we can still scroll back meanwhile +K clears it completely—we can't scroll back.

I like using it because I can always press ctrl+R or type:

history | grep command-that-I-want-to-do-again

if I want to re-type a command without a need to look at "messy character crowded" Terminal.

  • There is also Ctrl+L which is a shortcut for clear. – ManuelSchneid3r Jan 10 '14 at 11:59

In Terminal's Help menu, you can search for man pages. (The first time you do this, it can take a few seconds to index the man page files, so wait a bit for results to appear, but subsequent searches are fast.) It will show man page results in the Help menu search results. Selecting one opens a window displaying the formatted page.

As of Mac OS X Lion 10.7, there are a number of enhancements to man page support:

  • Man page searching lets you supply section numbers/names in various formats: "2 open", "open 2", "open(2)". It also supports asterisk "*" for wildcard searches.
  • It now searches all the files in MANPATH (prior to Lion it only searched a fixed set of directories, so, for example, it didn't find any X11 man pages). It doesn't run in a shell, however, so if you want to customize MANPATH you may need to customize man.conf (x-man-page://1/man), or set it in your global environment.
  • There are commands in the Help menu for opening man pages (Open man Page for Selection) and performing an apropos search (Search in man Pages for Selection). There are corresponding commands in the contextual menu, and there are Services you can enable to perform these lookups from other applications (System Preferences > Keyboard > Keyboard Shortcuts > Services > Open man Page in Terminal / Search man Pages in Terminal).
  • If there is no selected text, Open man Page for Selection will automatically look at the text to the left of the cursor. This means you can enter a command name, then use this command to open the man page before entering command arguments. It'll skip over whitespace. It also understands man page references "open(2)" and URLs "x-man-page://2/open". (If you explicitly select text, it also understands "2 open" and "open 2".)
  • Man page windows use the "Man Page" settings profile. You can customize this to alter the appearance of man pages displayed using these commands. It also remembers the position of man page windows separately from other windows, so you can have man pages appear in the same place on screen each time, independent of where you place other terminal windows.
  • + double-click will open man page references "open(2)", enabling you to navigate references from one man page to another. (+ double-click will also open any recognized URL, or even some patterns like email addresses—creates a new mail message—and domain names—opens in Safari.)
  • When viewing a man page window (or any terminal whose commands have all completed/exited), Terminal supports some "less"-compatible pager commands: space = Page Down, +space = Page Up, F = Page Down ("forward"), B = Page Up ("back"), = Scroll down one line, / = Scroll up/down one line.

I have the following aliases and functions in ~/.bash_profile:

alias ..="cd .."
alias ...="cd .. ; cd .."
alias ls="ls -G" # list
alias la="ls -Ga" # list all, includes dot files
alias ll="ls -Gl" # long list, excludes dot files
alias lla="ls -Gla" # long list all, includes dot files
alias stfu="osascript -e 'set volume output muted true'"
alias pumpitup="sudo osascript -e 'set volume 10'"
alias ips="ifconfig -a | perl -nle'/(\d+\.\d+\.\d+\.\d+)/ && print $1'"
alias myip="dig +short"
alias flush="dscacheutil -flushcache"
alias gzip="gzip -9n"
alias ping="ping -c 5"
alias ql="qlmanage -p 2>/dev/null" # preview a file using QuickLook

# Create a new directory and enter it
md() { mkdir -p "$@" && cd "$@"; }

# Define a term using Google
define() { local y="$@"; curl -sA "Opera" "${y// /+}" | grep -Po '(?<=<li>)[^<]+'|nl|perl -MHTML::Entities -pe 'decode_entities($_)' 2>/dev/null; }

# gzip a file with strongest compression settings
ubergzip() { gzip -9n < "$@" > "$@".gz; }

# Open a man page in
pman() { man -t "${1}" | open -f -a /Applications/; }

# Open a man page in
tman() { MANWIDTH=160 MANPAGER='col -bx' man $@ | mate; }

# Quit an app cleanly
quit() {
    for app in $*; do
        osascript -e 'quit app "'$app'"'

# Relaunch an app
relaunch() {
    for app in $*; do
        osascript -e 'quit app "'$app'"';
        sleep 2;
        open -a $app

# Uninstall an app with AppZapper
zap() { open -a AppZapper /Applications/"${1}".app; }

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

net rpc shutdown --server=<servername> --username=<username>

This will shut down windows boxes.

  • This is part of the Samba suite, so not OS X specific. – EmmEff Oct 11 '09 at 13:31

Command line shortcuts to toggle visibility of hidden files in finder:

alias show_hidden="defaults write AppleShowAllFiles TRUE && killall Finder"
alias hide_hidden="defaults write AppleShowAllFiles FALSE && killall Finder"

Here is a script that gets the path(s) to the current selection(s) in Finder:


osascript` << EOT

tell application "Finder"       
        set theFiles to selection
        set theList to ""
        repeat with aFile in theFiles
                set theList to theList & POSIX path of (aFile as alias) & " "
        end repeat
end tell


How I use it:

$ cat `selected`

Ok, definitely not mac specific, but TAB completion in zsh is so good I think it deserves a specific mention.

You get completion of options, e.g.

find . -d[TAB]

will give you -daystart -delete -depth as possible completions.

Also path completion is improved over Bash completion, for example, I have a Volume called Wubly, and inside that video/tv/comedy, so typing:

cd /v/w/v/t/co[TAB] 

will expand to.

cd /Volumes/Wubly/Video/TV/Comedy

(note that it's also case insensitive.)

If there are multiple paths that match this pattern, they will be shown.

Completion is also interactive, so you can move around the available choices with the cursor controls.

As of Mac OS X Lion 10.7, Terminal will open a new window if you drag a folder (or a text pathname) onto the application icon. If you drag to the tab bar of an existing window, it will create a new tab in that window.

You can also do this from the command line or a shell script:

open -a Terminal /some/path/

This is the command-line equivalent of dragging a folder onto the Terminal application icon and will open a new terminal window at "/some/path".

Terminal also now supports Services for opening a terminal at a selected folder (e.g., in Finder) or a text pathname using the contextual menu. You can enable them in

System Preferences > Keyboard > Keyboard Shortcuts > Services

Look for New Terminal at Folder and New Terminal Tab at Folder. You can even assign command keys to them if you like.

Finally, if you drag a folder or pathname onto an existing tab (i.e., the tab in the tab bar) and the foreground process is the shell, it will execute a "cd" command in one step. As in previous versions, dragging a folder onto the terminal display will insert the pathname to the folder.

  • iTerm supports dragging folders onto the icon in 10.6. – Fake Name Aug 26 '11 at 13:07
  • Terminal supported this from long ago – ocodo Dec 31 '13 at 4:01
  • @Slomojo are you responding to Fake Name or are you trying to correct my statement that Terminal supports this starting in 10.7? (Or did you not notice that I wrote that?) – Chris Page Jan 4 '14 at 11:15
  • @ChrisPage Terminal did this from several versions before 10.7, although I can't currently verify it firsthand before 10.6 (as I don't have a box running older versions) - FYI Cmd-c on a file / folder in Finder and Cmd-v in Terminal will also paste in the full path (same OSX version history.) – ocodo Jan 4 '14 at 11:20
  • @Slomojo I have confirmed that it did not until 10.7. – Chris Page Jan 4 '14 at 11:27

Flush the DNS cache if you are editing /etc/hosts a lot to test staging servers as looking like production.

dscacheutil -flushcache
  • Use it all the time! – daviesgeek Sep 6 '11 at 20:32

If you need to open a Finder window as the root user, you can execute the following from the terminal:

In 10.5 and below:

sudo /System/Library/CoreServices/

In 10.6:

sudo /System/Library/CoreServices/

Then, open a new finder window. You'll see that the new finder window opens with root permissions.

  • 1
    When is it useful to open a Finder window as the root user? – mjs Jul 26 '10 at 19:44

If you’re like me, you have multiple tabs open at the same time.

Now, if you open three tabs at the same point in time, then enter some commands in each of them, then close them all, the Bash shell that uses only remembers the command history for the last tab that you close. So, the command history from the other two tabs gets lost.

If you don’t want to lose your command history in any tab, add this to your ~/.bash_profile (or any other file that gets sourced when a new Terminal tab is opened):

# Append to the Bash history file, rather than overwriting it
shopt -s histappend

When cding, one of the most useful features is tab completion.

For example, instead of entering cd FooBarBazBax, you can enter cd FooB followed by Tab. Tab completion will work as long as the part of the path or filename you entered isn’t ambiguous.

However, if you were to type cd foob followed by Tab, the completion wouldn’t work, as the folder name starts with an uppercase F. Luckily, you can make tab completion even more useful by making it ignore the filename case.

Add this to your ~/.inputrc file (create the file if you don’t have it already):

# Make Tab autocomplete regardless of filename case
set completion-ignore-case on

This way, cd foob followed by Tab would complete it into cd FooBarBazBax, provided there’s a folder with that name in the current working directory.

Just type


and it will make inactive memory as free again. Mac OS X keeps apps in memory for a while after you close them, so they will open fast if you open them again. Purge will remove them from memory and give your free memory back.

This is more a Terminal meta-hint - you can use

Cmd-Shift-{Left arrow, Right Arrow} 

(Command Shift combined with left or right arrow) to quickly cycle between open windows.

  • 1
    On my Snow Leopard (Belgian keyboard) it's Cmd-Shift-Arrow, not just Cmd-Arrow. – Eric Darchis Aug 9 '10 at 16:39

Simulate to type Command-F, to fullscreen a video from command line. Useful when launching a movie in mPlayer from ssh.

osascript <<END
tell application "System Events" to keystroke "f" using {command down}

Of course you can also use this trick to simulate any other "typing".

  • FYI - iTerm2 has an instant replay function, very useful for making screencasts. – ocodo Jan 29 '11 at 9:24

what about

cat somefile.txt | say

say the contents of a text file... or...

cat someFile.txt | say -o someAudioFile

take your text file, convert it to .aiff

This is not OSX specific (man says it's from 4.0BSD), but I love it anyways:

sudo shutdown -h +45

In the above example, shutdown shuts down your computer in 45 minutes from now (as one might suspect).

It's great for when you want to spend "just a little bit of time" on your computer before going to bed / doing the dishes / going jogging / whatever. But when you also know deep down that it's not going to be "just a little bit of time"...


  • Love shutdown! – daviesgeek Oct 21 '11 at 5:27

You can set the system volume automatically too, and kill the screen process afterwards:

(hit enter)
sleep 300; osascript -e "set Volume 10"; say "I am feeling fabulous"; open ""; killall SCREEN
  • Why'd this get downvoted - not funny or not appropriate? Have a sense of humor people! – Brian Armstrong Jul 7 '10 at 18:40
  • What video was that? It's been removed from Youtube. – Jonik Jul 26 '10 at 18:03
  • So awesome!!!!! – daviesgeek Sep 6 '11 at 20:23

Text file to an Audio file

say -o “audiofile.aiff” -f “textfile.rtf”

more syntax here

If you use subversion, opens FileMerge for local checked out files that have been changed.

Requires installation of fmscripts:

cd ~/Downloads && svn co && cd fmscripts
sudo make

alias sfmdiff='svn diff --diff-cmd fmdiff'

Then in a checked out directory:

sfmdiff . 

(or any specific dir or file)

I include all my favorites here:


Set Volume to 10 and Say something

sudo osascript -e "set Volume 10" | say "hello World"

Wait for network to be ready in a script

/usr/sbin/networksetup -detectnewhardware

ctrl-R will allow you to perform a reverse search within your bash shell. It's like an interactive form of history.

  • duplicate of another answer – sourcedelica Jan 13 '14 at 0:20

gzip a file with strongest compression settings:

ubergzip() { gzip -9n < "$@" > "$@".gz; }

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

Define a term using Google:

define() { local y="$@"; curl -sA "Opera" "${y// /+}" | grep -Po '(?<=<li>)[^<]+'|nl|perl -MHTML::Entities -pe 'decode_entities($_)' 2>/dev/null; }

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

A relevant command for on Mac OS X is to launch Software Update from the CLI:

sudo softwareupdate -i -a

The bonus is you do not get any nagging from having to click on windows. I run this as part of a update script that is run every week approximately (so that I do not miss the feedback as it may happen when doing this automatically).

  • What does this do when there's an update that requires a restart? – Jason Salaz Mar 25 '12 at 22:26
  • @JasonSalaz It just prints a message suggesting to restart the OS (but doesn't force a restart or anything). – user495470 Apr 26 '12 at 7:34
  • using 'softwareupdate -l' is great too just to get a list as well. The Mac App Store in ML doesn't show the size of downloads all the time, but using this tool does. – jmlumpkin Aug 3 '12 at 2:46

Change directory to the directory shown in the top-most Finder window:

cdf () {
   currFolderPath=$( /usr/bin/osascript <<-EOT
       tell application "Finder"
               set currFolder to (folder of the front window as alias)
           on error
               set currFolder to (path to desktop folder as alias)
           end try
           POSIX path of currFolder
       end tell
   echo "cd to \"$currFolderPath\""
   cd "$currFolderPath"

Another version:

f() {
    cd "$(osascript -e 'try
tell app "Finder" to (target of Finder window 1) as text
POSIX path of result
on error
    (system attribute "HOME") & "/Desktop"
  • Note that in Mac OS X Lion 10.7 and later, Terminal provides a “New Terminal at Folder” service that you can use to open a terminal by selecting a folder and choosing the command from the Finder > Services menu or by Control-Clicking and choosing it from the contextual menu. (You’ll need to enable the service in System Preferences > Keyboard > Keyboard Shortcuts > Services.) You can also drag a folder onto the Terminal application icon in the Dock, or into a tab bar to create a new tab in an existing window. – Chris Page May 3 '12 at 7:36

Quick Look is one of OS X's best features. You just have to press Spacebar in a selected file, and you'll see a preview of that file without having to open up an app. It's great, but you can't select any text when you're in the preview. You can add that feature with a Terminal command:

defaults write QLEnableTextSelection -bool true 
killall Finder

Use the feature of Quick Look, select the text you want, and now you could copy it.

Mount iDisk from command line:

osascript <<END
tell application "Finder"
mount volume "" as user name "john.doe" with password "StR0NGP455"
end tell

Not the answer you're looking for? Browse other questions tagged or ask your own question.