132

I want to open videos and pictures from my command line shell.

Is there a way terminal app can do this?

bmike
  • 235,889

3 Answers3

187

To open any file from the command line with the default application, just type open followed by the filename/path.

Example:

open ~/Desktop/filename.mp4

Edit: as per Johnny Drama's comment below, if you want to be able to open files in a certain application, put -a followed by the application's name in quotes between open and the file.

Example:

open -a "QuickTime Player" ~/Desktop/filename.mp4

If you need further information about the open command, type man open.

Tuesday
  • 15,204
  • 11
    Just to complete this answer: With timotyhm's command you will open the file with the default application for this filetype. If you want to open any file with a specific application, just enter: open -a "Application" /Path/to/file. Example: open -a "Adobe Photoshop CC 2014" ~/Desktop/test.psd. See man open for more information. – joni Oct 25 '15 at 08:05
  • 1
    @JohnnyDrama Good point. Can I edit that into my answer? – Tuesday Oct 25 '15 at 15:39
  • 3
    The collaboration in answers is awesome. Johnny Drama's answer is what I really wanted, but the title is what I searched. Answers like these are why I love StackExchange! – mbm29414 Sep 30 '16 at 13:16
  • 2
    This does not work. 18.04. jpg. – mathtick Dec 02 '18 at 14:50
  • To complete the answer even more, if you have multiple apps with the same name (e.g. you're developing and have an app store version and a debug version), you can specify a path to the app. Example: open -a /path/to/MyApp.app /path/to/file.txt – Patrick Mar 21 '22 at 04:08
2

I wrote a guide on how to open a file in terminal which includes instructions for Windows and Linux as well, but to summarize for both the OP and others who find this page (to be complete, I showed how to do this in command prompt as well):

Navigate to the file's directory: cd /path/to/directory

Open the file: In macOS open filename.txt or use editors like vi, emacs, nano. Example:

vi filename.txt

Opening Other Files in Terminal:

macOS: PDFs: open filename.pdf

Images: open filename.jpg

Webpages: open http://www.example.com

0

It can also be done by using xdg-open filename. Command will open the file with it's default application and it also used to open the urls .

nohillside
  • 100,768
  • xdg-open is not a stock Mac OS X tool. – lhf Jan 02 '18 at 17:49
  • 2
    xdg-open is on Linux and macOS is not Linux! The accepted answer has the default macOS command line app, open. – user3439894 Jan 02 '18 at 17:58
  • 1
    Awkwardly this question is the top google hit for "linux open any file". So while this is not a correct answer for the question asked, it is really handy to have this listed highly. I can't bring myself to vote this answer up, but I will vote the other wrong answers down to ensure this stays prominent. – LovesTha Oct 07 '20 at 22:21
  • 1
    You’re correct @LovesTha - would it be good to ask and answer a question on Linux or Unix specific sites here so it can be found better and be on topic? – bmike Oct 19 '23 at 18:44