Opening Finder Windows from the Terminal

Dec 15, 2009 - 8 Comments

The Finder of Mac OS X Finder, the OS X file system browser, is ultimately just a nice looking GUI application, and it can be interacted with fluidly from the command line. This means you can jump to directories and open literally any Mac Finder window directly from the terminal by using a simple command string based upon the ‘open’ command. The general syntax to use for this is as follows:

open /Path/To/Directory/

For example, if you want to open the folder which contains the aforementioned Finder application (which would then allow you to open it with a double-click), you can use the following command syntax:

open /System/Library/CoreServices/

Opening the Root directory in Finder is simple too:

open /

Opening the User Home Directory can be achieved as follows:

open ~

What if you’re buried deep in the file system within the Terminal, and need to open that deep path in the Finder? Immediately accessing the present working directory in a new Finder window is quickly achieved by typing the following command string in the Terminal:

open .

The “.” (period) has long been a UNIX reference to the present working directory (PWD, sometimes called Current Working Directory or CWD), and it changes according to where the terminal is located. For instance, if you have just launched Terminal which defaults to the users home folder, typing that in the command line will immediately open your home directory, but you can be anywhere and it works the same. Using ‘open’ from the command line to jump to the Current Folder (PWD) in the Finder was discussed here specifically.

You can also specify directories to open from the terminal into the Finder, like so:

open /Applications/Utilities/

This opens your utilities app folder. Try it with just about anything.

This can make for a great way to leap to deeply embedded system directories thanks to tab-completion:

open /System/Library/Application\ Support/iTunes/Defaults/Preferences/

Note that Open can also be used to launch applications and perform other tasks. This provides the ‘open’ command the ability to relaunch applications that are system specific, like any other app. Staying on the “Finder” topic, the Finder application can be launched like another app if it has crashed or is quit for some reason. To do that, simply enter the following command string into the terminal:

open /System/Library/CoreServices/Finder.app

Again, this can used for any other application throughout OS X, just be sure to point it at the app.

If it’s not working to launch the app in question, sometimes you may need to point the open string at the applications binary contained within the .app package instead, like so:

open /Applications/Sample.app/Contents/MacOS/Sample

The precise location of the application binary may vary per individual application, when in doubt look within the “name.app/Contents/” directories to find it.

The next logical question may be how to do this in reverse; that is, how to open a new Terminal.app window set to the present directory as viewed in Finder. It turns out such a feature exists in OS X Services, though a user must enable the “New Terminal at Folder” service to gain such functionality, which is then accessible with a Right-Click on any directory within Finder.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: Paul Horowitz in Command Line, Mac OS X, Tips & Tricks

8 Comments

» Comments RSS Feed

  1. Bruce says:

    Is there a way to make it so that we can run this via a shortcut? That would be super helpful.

  2. Chromeo says:

    bruce, shortcut to what? open is pretty short?

  3. Carl says:

    Humm…. is it november 30th all over again? I didn’t think you would recycle hints on such a short time frame. :P

  4. Bill Ellis says:

    @Carl, oops! Thanks for pointing this out!

  5. Bruce says:

    @Chromeo I’m saying like a Command + F to open the finder (most likely not that exact shortcut but something similar).

  6. Andre says:

    Hi, i want to open folder in Finder and select file via command line. Any idea?
    Thanks!
    Andre

  7. Steve Bennett says:

    FYI, the Windows equivalent is: start .

  8. Wolfgang says:

    This does not work any more with 10.9 mavericks. Is there a fix?

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates