The macOS open command hands a file, folder, or URL to whatever app the system would use if you double-clicked it. The whole point is that it bridges the Terminal and the GUI: you stay in the shell, but the thing you are opening lands in the right Mac app. The shortest useful version:
open report.pdfThat opens report.pdf in your default PDF app (usually Preview), exactly as a double-click in Finder would. No flags, no app name, no path gymnastics. The rest of this page is the variations I actually reach for: a specific app, the current folder, a URL in a chosen browser, and the one zsh gotcha that silently breaks URLs.
Open a file in its default app
Pass open a path and it asks LaunchServices which app owns that file type, then launches it:
open notes.md # opens in your default Markdown/text app
open photo.heic # opens in Preview (or whatever you set)
open archive.zip # hands it to Archive Utility, which unzips itThis is the everyday case. The file extension drives the choice, so the same open data.csv lands in Numbers on one Mac and in Excel on another, depending on what each machine has set as the default for that type.
Open the current folder in Finder
open . opens the current working directory in a Finder window. This is the one I use most:
open . # current directory in Finder
open ~/Downloads # any folder
open .. # parent directoryIt is the fastest way to jump from a deep terminal path into a Finder window without re-navigating by hand. A bare open with a directory argument opens that directory; open . is just the special case for "right here."
Open with a specific app: open -a
To force a particular app instead of the default, use -a with the app name. The name is case-insensitive and you do not include .app:
open -a "Visual Studio Code" server.js
open -a Preview diagram.png
open -a "Sublime Text" .If the app name has a space, quote it. open -a "Google Chrome" works, open -a Google Chrome tries to open an app called Google and then a file called Chrome. When the named app is not installed, open fails with Unable to find application named '...', which is the usual sign of a typo or a wrong name (it is "Visual Studio Code", not "VS Code").
There is also -b, which targets an app by its bundle identifier rather than its display name. That is steadier in scripts because a bundle ID does not change when Apple renames an app:
open -b com.apple.TextEdit notes.txtOpen a file in TextEdit or the default editor
Two shortcuts skip the app-name dance for editing plain text. -e always uses TextEdit; -t uses whatever app is registered as the default editor for that file type:
open -e config.txt # always TextEdit
open -t config.txt # default text editor (could be BBEdit, VS Code, etc.)I reach for -e when I want a quick, no-surprises text window and do not care what my default editor happens to be set to.
Open a URL in the default browser
Give open an http or https URL and it opens in your default browser:
open https://techearl.comThis is handy at the end of a script ("build done, open the local preview") or just to fling a link from the terminal into a browser tab.
Open a URL in a specific (non-default) browser
This is the combination people search for and miss: -a plus a URL opens that URL in the named browser, regardless of which browser is your system default.
open -a "Safari" https://techearl.com
open -a "Firefox" https://techearl.com
open -a "Google Chrome" https://techearl.comSo if Safari is your default but you want to check a page in Firefox, open -a Firefox <url> does it without changing any settings. To pass command-line flags through to the browser itself, use --args (everything after it goes to the app, not to open). For example, telling Chrome to make itself the default browser:
open -a "Google Chrome" --args --make-default-browserThere is no general "set default browser from the command line" command on macOS; that Chrome-specific flag is the closest thing, and it only works because Chrome itself understands --make-default-browser. On recent macOS it does not flip the default silently either: it triggers the system "Use Chrome as your default browser?" confirmation dialog, which you still have to approve by hand.
The zsh quoting gotcha (quote your URLs)
This one bites people on every modern Mac. Since Catalina, the default shell is zsh, and zsh treats ?, &, and # as special characters. An unquoted URL with a query string gets mangled before open ever sees it:
open https://example.com/search?q=mac&page=2 # zsh breaks this
open 'https://example.com/search?q=mac&page=2' # quote it, worksWithout quotes, zsh tries to glob the ? and treats & as "run in background," so you get a no matches found error or a half-eaten URL. Always single-quote a URL that contains ?, &, or #. It is a good habit even in bash; in zsh it is mandatory.
Reveal a file in Finder instead of opening it
-R selects and highlights a file in a Finder window rather than opening it. Useful when you want to see a file in context, not launch it:
open -R ~/Projects/site/dist/index.htmlThe Finder window opens at the enclosing folder with the file selected, ready to drag, rename, or look at alongside its neighbors.
Other flags worth knowing
A few more from the open(1) man page that earn their keep:
open -n -a Safari # force a NEW instance even if Safari is running
open -g -a Music song.m4a # open in the background, do not steal focus
open -W -a Preview scan.pdf # wait until that app quits before the shell continues-n matters when you genuinely want a second copy of an app running. -g is nice in scripts that should not yank you out of the terminal. -W (wait) lets you script "open this, and do the next step only after I close it." You can also pass several files at once: open *.png opens every PNG in the folder in the default image app.
Linux and Windows equivalents
open is macOS only. On Linux the equivalent is xdg-open file-or-url (from xdg-utils), which hands the target to your desktop environment's default handler. On Windows the rough equivalent is start file-or-url in cmd (note start opens a URL or document with the registered handler). If you write cross-platform scripts, those are the two names to branch on.
FAQ
See also
- Copy to the clipboard from the command line with pbcopy and pbpaste: the other macOS-only Terminal-to-GUI bridge, with the Linux and Windows equivalents.
- Set the date and time from the macOS command line: the BSD vs GNU divergence that trips up Mac sysadmins, in the same vein as the zsh quoting gotcha here.
- Get a saved Wi-Fi password from the Mac Terminal: another built-in macOS command that does a job people reach for a third-party tool to do.
Sources
Authoritative references this article was fact-checked against.
- open command reference (ss64, mirrors the open(1) man page)ss64.com
- The macOS open command (Scripting OS X)scriptingosx.com
- open(1) — macOS manual pageunix.com





