Terminal 101: The Open Command

Every Monday, we'll show you how to do something new and simple with Apple's built-in command line application.

Every Monday, we'll show you how to do something new and simple with Apple's built-in command line application. You don't need any fancy software, or a knowledge of coding to do any of these. All you need is a keyboard to type 'em out!

Whether you’ve found a file through searching for it in the Terminal, or just want to open a document in a native Mac application for editing, then the Open command is for you. This command will automatically open your files with a default Mac app that can handle the file type it’s associated with. This means that you don’t have to tinker with learning a new Terminal program to quickly edit your files (unless you really want to).

Opening One File

If you just want to open one file with the default application associated with that file type on your Mac, then you can use the following command to do your bidding:

open file.txt

Replace “file.txt” with the directory path and file that you wish to open. When you press enter, a Mac app will launch, opening the file you’ve specified.

Opening Multiple Files

Let’s say you found multiple files in a search of your drive, and you now want to open those with native Mac applications. Well, this is easier than you think. To do this, use the following command:

open myFile1 myFile2 myFile3

Replace myFile1, myFile2, and myFile3 with the paths and file names of the files that you wish to open. You can keep on adding file names as you like, ensuring there is a single space in between each of the filenames that you wish to open.

Choosing the Application

You may not always want the default application on your Mac to handle the opening of a particular file. In this instance, you can use the following flag on the open command to choose the app you wish to open the file with:

open -a appName fileName

Replace appName with the name of the app you wish to open the file with, and replace fileName with the path and name of the file you wish to open. For example, if we had a file called “myFile.rtf” that we wanted to open with Pages, we could type the following command:

open -a pages myFile.rtf

When you press the enter key, the Pages application will launch, opening the file that you specified. This will work with any application installed on your Mac located in your Applications folder.

Cory Bohon is a freelance technology writer, indie Mac and iOS developer, and amateur photographer. Follow this article's author on Twitter.