Terminal 101: The Open Command

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.