--- layout: page category_title: Basic commands category-page: basic tags: open author: Gianmarco De Vita title: open ---

You can open files and folder as new windows through the terminal. The command is open. By writing the command open followed by the path and the name of the file (remember that you can omit the path if the file is in the current position), a new window in the common user interface opens. Now you can work on the opened file.

Device-name:Current-position username$ open path/name-file

Open a file with a specific application

Adding the flag -a to the command permit you to decide with which specific application open the file. Just write the flag followed by the name of the application.

Device-name:Current-position username$ open -a application-name path/name-file

Example

Assume that I want to open with Preview the file abc.pdf on my Desktop. I have to write:

User-Device:~ user$ open -a preview Desktop/abc.pdf

As result, a new Preview window appears in pop up showing the content of the chosen file.

Open a file with TextEdit

If you want to open a file with TextEdit, just use instead of -a the flag -e and write the path and the name of the file you want to open.

User-Device:~ user$ open -e Desktop/text.txt

Open the folder which contains the file

If you want to open the folder that contains a specific file, just use the flag -R and write the path and the name of the file you want to open.

User-Device:~ user$ open -R Desktop/text.txt

As result, a new Finder window opens the folder displaying its content.

Open a file as a text

If you want to open a file with your default text editor (determined via LaunchServices), just use the flag -t and write the path and the name of the file you want to open.

User-Device:~ user$ open -t Desktop/text.txt

Visit a Website

You can use this tool not only to open files and folders, but also webpages. Just write the command open followed by the URL of the page you want to visit. For example, by typing the command

User-Device:~ user$ open http://www.google.com

A new page of your default browser will open on the indicated page (in this example, the main page of the Google Search Engine).