How to open file with default application from command line?












170















In Nautilus, when you double click a file, it will open it with the default application associated with the file's extension. For instance, .html files will open in a web browser and .pdf will be opened with Document Viewer. Is there a way to reproduce the same behavior from within the command line (i.e. open path/filename)? I'm asking because I like to browse my file-system from the command line but sometimes don't remember which app. opens what.










share|improve this question

























  • There is a similar question regarding launching default browser from the command line: askubuntu.com/questions/8252/…

    – kounryusui
    Nov 29 '10 at 13:42











  • That's a brilliant question indeed! In almost 4 years of my bashing I hadn't thought about it :P

    – John Strood
    Jun 7 '16 at 9:40
















170















In Nautilus, when you double click a file, it will open it with the default application associated with the file's extension. For instance, .html files will open in a web browser and .pdf will be opened with Document Viewer. Is there a way to reproduce the same behavior from within the command line (i.e. open path/filename)? I'm asking because I like to browse my file-system from the command line but sometimes don't remember which app. opens what.










share|improve this question

























  • There is a similar question regarding launching default browser from the command line: askubuntu.com/questions/8252/…

    – kounryusui
    Nov 29 '10 at 13:42











  • That's a brilliant question indeed! In almost 4 years of my bashing I hadn't thought about it :P

    – John Strood
    Jun 7 '16 at 9:40














170












170








170


47






In Nautilus, when you double click a file, it will open it with the default application associated with the file's extension. For instance, .html files will open in a web browser and .pdf will be opened with Document Viewer. Is there a way to reproduce the same behavior from within the command line (i.e. open path/filename)? I'm asking because I like to browse my file-system from the command line but sometimes don't remember which app. opens what.










share|improve this question
















In Nautilus, when you double click a file, it will open it with the default application associated with the file's extension. For instance, .html files will open in a web browser and .pdf will be opened with Document Viewer. Is there a way to reproduce the same behavior from within the command line (i.e. open path/filename)? I'm asking because I like to browse my file-system from the command line but sometimes don't remember which app. opens what.







command-line






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 21 '14 at 18:37









Radu Rădeanu

119k35252328




119k35252328










asked Nov 29 '10 at 12:07









Olivier LalondeOlivier Lalonde

21.2k51112141




21.2k51112141













  • There is a similar question regarding launching default browser from the command line: askubuntu.com/questions/8252/…

    – kounryusui
    Nov 29 '10 at 13:42











  • That's a brilliant question indeed! In almost 4 years of my bashing I hadn't thought about it :P

    – John Strood
    Jun 7 '16 at 9:40



















  • There is a similar question regarding launching default browser from the command line: askubuntu.com/questions/8252/…

    – kounryusui
    Nov 29 '10 at 13:42











  • That's a brilliant question indeed! In almost 4 years of my bashing I hadn't thought about it :P

    – John Strood
    Jun 7 '16 at 9:40

















There is a similar question regarding launching default browser from the command line: askubuntu.com/questions/8252/…

– kounryusui
Nov 29 '10 at 13:42





There is a similar question regarding launching default browser from the command line: askubuntu.com/questions/8252/…

– kounryusui
Nov 29 '10 at 13:42













That's a brilliant question indeed! In almost 4 years of my bashing I hadn't thought about it :P

– John Strood
Jun 7 '16 at 9:40





That's a brilliant question indeed! In almost 4 years of my bashing I hadn't thought about it :P

– John Strood
Jun 7 '16 at 9:40










3 Answers
3






active

oldest

votes


















221














I think xdg-open is the command you are looking for.



NAME
xdg-open - opens a file or URL in the user's preferred application

SYNOPSIS
xdg-open {file | URL}

xdg-open {--help | --manual | --version}

DESCRIPTION
xdg-open opens a file or URL in the user's preferred application. If a
URL is provided the URL will be opened in the user's preferred web
browser. If a file is provided the file will be opened in the preferred
application for files of that type. xdg-open supports file, ftp, http
and https URLs.


eg: xdg-open index.php



This will open index.php in gedit(if you are using gnome).



If you want to open a url in browser



xdg-open http://google.com


this will open google.com in your default browser.





xdg-open is a wrapper script - it will use the desktop environment's tool (gio open, gvfs-open, kde-open, gnome-open, dde-open, exo-open, and a host of other such tools). It is also installed by default, and very likely to work on past, current and future versions (on the other hand, gvfs-open and gnome-open have been deprecated, and may be unavailable in future releases).






share|improve this answer





















  • 3





    wish I searched on google for this earlier

    – JohnMerlino
    Sep 25 '13 at 23:55






  • 2





    On Gnome: gnome-open and on KDE: kde-open works.

    – Farahmand
    Feb 21 '14 at 16:01











  • xde-open worked on xfce as well.

    – Seven
    Dec 13 '16 at 4:30






  • 4





    easy way to shorten this command is to use an alias. alias o='xdg-open'. Put this inside your .bash_aliases file to make the alias load on startup each time. nano ~/.bash_aliases and then paste inside nano using CTRL+SHIFT+V.

    – anon58192932
    Sep 21 '17 at 15:44





















46














xdg-open and gnome-open



xdg-open is the most universal way (work also on KDE)






share|improve this answer



















  • 4





    This answer was posted earlier.

    – Kadir
    Jan 15 '15 at 11:44



















10














If you want to:




  • make an alias for this command (e.g. open)

  • hide output from the command

  • continue using this terminal after


You can use this .bashrc function:



function open () {
xdg-open "$@">/dev/null 2>&1
}





share|improve this answer

























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "89"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f15354%2fhow-to-open-file-with-default-application-from-command-line%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    221














    I think xdg-open is the command you are looking for.



    NAME
    xdg-open - opens a file or URL in the user's preferred application

    SYNOPSIS
    xdg-open {file | URL}

    xdg-open {--help | --manual | --version}

    DESCRIPTION
    xdg-open opens a file or URL in the user's preferred application. If a
    URL is provided the URL will be opened in the user's preferred web
    browser. If a file is provided the file will be opened in the preferred
    application for files of that type. xdg-open supports file, ftp, http
    and https URLs.


    eg: xdg-open index.php



    This will open index.php in gedit(if you are using gnome).



    If you want to open a url in browser



    xdg-open http://google.com


    this will open google.com in your default browser.





    xdg-open is a wrapper script - it will use the desktop environment's tool (gio open, gvfs-open, kde-open, gnome-open, dde-open, exo-open, and a host of other such tools). It is also installed by default, and very likely to work on past, current and future versions (on the other hand, gvfs-open and gnome-open have been deprecated, and may be unavailable in future releases).






    share|improve this answer





















    • 3





      wish I searched on google for this earlier

      – JohnMerlino
      Sep 25 '13 at 23:55






    • 2





      On Gnome: gnome-open and on KDE: kde-open works.

      – Farahmand
      Feb 21 '14 at 16:01











    • xde-open worked on xfce as well.

      – Seven
      Dec 13 '16 at 4:30






    • 4





      easy way to shorten this command is to use an alias. alias o='xdg-open'. Put this inside your .bash_aliases file to make the alias load on startup each time. nano ~/.bash_aliases and then paste inside nano using CTRL+SHIFT+V.

      – anon58192932
      Sep 21 '17 at 15:44


















    221














    I think xdg-open is the command you are looking for.



    NAME
    xdg-open - opens a file or URL in the user's preferred application

    SYNOPSIS
    xdg-open {file | URL}

    xdg-open {--help | --manual | --version}

    DESCRIPTION
    xdg-open opens a file or URL in the user's preferred application. If a
    URL is provided the URL will be opened in the user's preferred web
    browser. If a file is provided the file will be opened in the preferred
    application for files of that type. xdg-open supports file, ftp, http
    and https URLs.


    eg: xdg-open index.php



    This will open index.php in gedit(if you are using gnome).



    If you want to open a url in browser



    xdg-open http://google.com


    this will open google.com in your default browser.





    xdg-open is a wrapper script - it will use the desktop environment's tool (gio open, gvfs-open, kde-open, gnome-open, dde-open, exo-open, and a host of other such tools). It is also installed by default, and very likely to work on past, current and future versions (on the other hand, gvfs-open and gnome-open have been deprecated, and may be unavailable in future releases).






    share|improve this answer





















    • 3





      wish I searched on google for this earlier

      – JohnMerlino
      Sep 25 '13 at 23:55






    • 2





      On Gnome: gnome-open and on KDE: kde-open works.

      – Farahmand
      Feb 21 '14 at 16:01











    • xde-open worked on xfce as well.

      – Seven
      Dec 13 '16 at 4:30






    • 4





      easy way to shorten this command is to use an alias. alias o='xdg-open'. Put this inside your .bash_aliases file to make the alias load on startup each time. nano ~/.bash_aliases and then paste inside nano using CTRL+SHIFT+V.

      – anon58192932
      Sep 21 '17 at 15:44
















    221












    221








    221







    I think xdg-open is the command you are looking for.



    NAME
    xdg-open - opens a file or URL in the user's preferred application

    SYNOPSIS
    xdg-open {file | URL}

    xdg-open {--help | --manual | --version}

    DESCRIPTION
    xdg-open opens a file or URL in the user's preferred application. If a
    URL is provided the URL will be opened in the user's preferred web
    browser. If a file is provided the file will be opened in the preferred
    application for files of that type. xdg-open supports file, ftp, http
    and https URLs.


    eg: xdg-open index.php



    This will open index.php in gedit(if you are using gnome).



    If you want to open a url in browser



    xdg-open http://google.com


    this will open google.com in your default browser.





    xdg-open is a wrapper script - it will use the desktop environment's tool (gio open, gvfs-open, kde-open, gnome-open, dde-open, exo-open, and a host of other such tools). It is also installed by default, and very likely to work on past, current and future versions (on the other hand, gvfs-open and gnome-open have been deprecated, and may be unavailable in future releases).






    share|improve this answer















    I think xdg-open is the command you are looking for.



    NAME
    xdg-open - opens a file or URL in the user's preferred application

    SYNOPSIS
    xdg-open {file | URL}

    xdg-open {--help | --manual | --version}

    DESCRIPTION
    xdg-open opens a file or URL in the user's preferred application. If a
    URL is provided the URL will be opened in the user's preferred web
    browser. If a file is provided the file will be opened in the preferred
    application for files of that type. xdg-open supports file, ftp, http
    and https URLs.


    eg: xdg-open index.php



    This will open index.php in gedit(if you are using gnome).



    If you want to open a url in browser



    xdg-open http://google.com


    this will open google.com in your default browser.





    xdg-open is a wrapper script - it will use the desktop environment's tool (gio open, gvfs-open, kde-open, gnome-open, dde-open, exo-open, and a host of other such tools). It is also installed by default, and very likely to work on past, current and future versions (on the other hand, gvfs-open and gnome-open have been deprecated, and may be unavailable in future releases).







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jun 16 '18 at 16:13









    muru

    1




    1










    answered Nov 29 '10 at 12:13









    aneeshepaneeshep

    22.4k115574




    22.4k115574








    • 3





      wish I searched on google for this earlier

      – JohnMerlino
      Sep 25 '13 at 23:55






    • 2





      On Gnome: gnome-open and on KDE: kde-open works.

      – Farahmand
      Feb 21 '14 at 16:01











    • xde-open worked on xfce as well.

      – Seven
      Dec 13 '16 at 4:30






    • 4





      easy way to shorten this command is to use an alias. alias o='xdg-open'. Put this inside your .bash_aliases file to make the alias load on startup each time. nano ~/.bash_aliases and then paste inside nano using CTRL+SHIFT+V.

      – anon58192932
      Sep 21 '17 at 15:44
















    • 3





      wish I searched on google for this earlier

      – JohnMerlino
      Sep 25 '13 at 23:55






    • 2





      On Gnome: gnome-open and on KDE: kde-open works.

      – Farahmand
      Feb 21 '14 at 16:01











    • xde-open worked on xfce as well.

      – Seven
      Dec 13 '16 at 4:30






    • 4





      easy way to shorten this command is to use an alias. alias o='xdg-open'. Put this inside your .bash_aliases file to make the alias load on startup each time. nano ~/.bash_aliases and then paste inside nano using CTRL+SHIFT+V.

      – anon58192932
      Sep 21 '17 at 15:44










    3




    3





    wish I searched on google for this earlier

    – JohnMerlino
    Sep 25 '13 at 23:55





    wish I searched on google for this earlier

    – JohnMerlino
    Sep 25 '13 at 23:55




    2




    2





    On Gnome: gnome-open and on KDE: kde-open works.

    – Farahmand
    Feb 21 '14 at 16:01





    On Gnome: gnome-open and on KDE: kde-open works.

    – Farahmand
    Feb 21 '14 at 16:01













    xde-open worked on xfce as well.

    – Seven
    Dec 13 '16 at 4:30





    xde-open worked on xfce as well.

    – Seven
    Dec 13 '16 at 4:30




    4




    4





    easy way to shorten this command is to use an alias. alias o='xdg-open'. Put this inside your .bash_aliases file to make the alias load on startup each time. nano ~/.bash_aliases and then paste inside nano using CTRL+SHIFT+V.

    – anon58192932
    Sep 21 '17 at 15:44







    easy way to shorten this command is to use an alias. alias o='xdg-open'. Put this inside your .bash_aliases file to make the alias load on startup each time. nano ~/.bash_aliases and then paste inside nano using CTRL+SHIFT+V.

    – anon58192932
    Sep 21 '17 at 15:44















    46














    xdg-open and gnome-open



    xdg-open is the most universal way (work also on KDE)






    share|improve this answer



















    • 4





      This answer was posted earlier.

      – Kadir
      Jan 15 '15 at 11:44
















    46














    xdg-open and gnome-open



    xdg-open is the most universal way (work also on KDE)






    share|improve this answer



















    • 4





      This answer was posted earlier.

      – Kadir
      Jan 15 '15 at 11:44














    46












    46








    46







    xdg-open and gnome-open



    xdg-open is the most universal way (work also on KDE)






    share|improve this answer













    xdg-open and gnome-open



    xdg-open is the most universal way (work also on KDE)







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 29 '10 at 12:11









    shellholicshellholic

    4,63111916




    4,63111916








    • 4





      This answer was posted earlier.

      – Kadir
      Jan 15 '15 at 11:44














    • 4





      This answer was posted earlier.

      – Kadir
      Jan 15 '15 at 11:44








    4




    4





    This answer was posted earlier.

    – Kadir
    Jan 15 '15 at 11:44





    This answer was posted earlier.

    – Kadir
    Jan 15 '15 at 11:44











    10














    If you want to:




    • make an alias for this command (e.g. open)

    • hide output from the command

    • continue using this terminal after


    You can use this .bashrc function:



    function open () {
    xdg-open "$@">/dev/null 2>&1
    }





    share|improve this answer






























      10














      If you want to:




      • make an alias for this command (e.g. open)

      • hide output from the command

      • continue using this terminal after


      You can use this .bashrc function:



      function open () {
      xdg-open "$@">/dev/null 2>&1
      }





      share|improve this answer




























        10












        10








        10







        If you want to:




        • make an alias for this command (e.g. open)

        • hide output from the command

        • continue using this terminal after


        You can use this .bashrc function:



        function open () {
        xdg-open "$@">/dev/null 2>&1
        }





        share|improve this answer















        If you want to:




        • make an alias for this command (e.g. open)

        • hide output from the command

        • continue using this terminal after


        You can use this .bashrc function:



        function open () {
        xdg-open "$@">/dev/null 2>&1
        }






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 14 '17 at 19:23

























        answered Dec 14 '17 at 15:29









        Jesse KnightJesse Knight

        21629




        21629






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Ask Ubuntu!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f15354%2fhow-to-open-file-with-default-application-from-command-line%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to change which sound is reproduced for terminal bell?

            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

            Can I use Tabulator js library in my java Spring + Thymeleaf project?