Opening Finder Windows from the Terminal
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:
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:
Opening the Root directory in Finder is simple too:
Opening the User Home Directory can be achieved as follows:
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:
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:
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:
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:
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.