16

How can I open a file in its default application from the command line?

For example if I have a file foo.doc, can I type command ./foo.doc into the CLI and have that file open in Word?

Note: on my linux machine, I would use xdg-open but that doesn't work on my Mac.

1 Answer 1

20

Use:

open foo.doc

or, alternatively:

open -n foo.doc

to force it to open a new instance if one is already open for that app.

4
  • 2
    open is a very good command to get to know.
    – Cajunluke
    Aug 15, 2012 at 16:34
  • 4
    open -n opens a new instance, not a window.
    – Lri
    Aug 15, 2012 at 16:37
  • 4
    Also nice is open . (or any directory name in place of .), which opens Finder (the default application for a directory). Aug 15, 2012 at 17:03
  • 1
    where could I set default preferred program that open opens for specific file type? ( it would be great if this preference stored somewhere, cause setting it by gui is very annoying ) Feb 25, 2016 at 12:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .