137

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

Is there a way terminal app can do this?

0

3 Answers 3

194

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.

5
  • 12
    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
    Commented Oct 25, 2015 at 8:05
  • 1
    @JohnnyDrama Good point. Can I edit that into my answer?
    – Tuesday
    Commented Oct 25, 2015 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
    Commented Sep 30, 2016 at 13:16
  • 2
    This does not work. 18.04. jpg.
    – safetyduck
    Commented Dec 2, 2018 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
    Commented Mar 21, 2022 at 4: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

3
  • 1
    Thanks for the answer. I’m not so sure the windows or Linux information will be greeted with up votes here. Perhaps linking to that detail hosted on another site as a footnote would be more appropriate?
    – bmike
    Commented Oct 17, 2023 at 20:05
  • @bmike thank you, I have removed the information for linux and windows Commented Oct 19, 2023 at 17:11
  • 1
    @agarza thank you for the edit. It looks great! Commented Oct 20, 2023 at 2:23
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 .

3
  • xdg-open is not a stock Mac OS X tool.
    – lhf
    Commented Jan 2, 2018 at 17:49
  • 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
    Commented Oct 7, 2020 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
    Commented Oct 19, 2023 at 18:44

You must log in to answer this question.

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