Skip to content
FLAVIO COPES
flaviocopes.com

Linux commands: open

By

Learn how the macOS open command opens a file, a folder in Finder, or an application, and why open . is so handy, with xdg-open as the Linux equivalent.

~~~

The open command lets you open a file using this syntax:

open <filename>

The file opens in the default app registered for that type, exactly as if you had double-clicked it in the Finder: open notes.txt launches your text editor, open photo.png your image viewer.

That is the point of this command. It bridges the terminal and the graphical side of macOS: you’re already in the shell, already in the right folder, and you don’t have to reach for the mouse to see something.

You can also open a directory, which on macOS opens the Finder app with the current directory open:

open <directory name>

I use it all the time to open the current directory:

open .

The special . symbol points to the current directory, as .. points to the parent directory

URLs work too. This opens your default browser on the site:

open https://flaviocopes.com

The same command can also be used to run an application. Pass the -a option followed by the application name:

open -a Calculator

-a is also how you open a file with a specific app instead of the default one:

open -a "Google Chrome" index.html

Note the quotes: an application name containing spaces must be quoted, or the shell splits it into separate arguments.

When something refuses to open, read the error message. open missing.txt fails with The file /Users/flavio/missing.txt does not exist. — nearly always a typo in the name or the wrong current directory. Run ls to check what’s actually there, then try again.

The open command works on macOS only. Use xdg-open on Linux

xdg-open covers the same jobs on Linux: files, folders, and URLs, each handed to the desktop’s default application.

Tagged: CLI · All topics
~~~

Related posts about cli: