1

Almost every desktop environment has a mechanism for determining what to do when you (double)-click a file in file manager/explorer windows. This can be based on the extension, or on whatever file does, etc.

Now, suppose I have a terminal window open within a desktop session and I'm at some folder. Is there some binary or script - hopefully valid across multiple desktop environments common to Linux - which, when executed with a filename as its argument, uses this mechanism and has the same effect as (double)-clicking that file would?

If there isn't a single multi-desktop-environment way to do this - are there a bunch of desktop-environment-specific binaries/scripts with this functionality? If so, can you list such a bunch?

On Windows I think this exists in the form of the start command (although, of course, they can assume a single desktop environment.)

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
einpoklum
  • 8,772
  • 19
  • 65
  • 129
  • 1
    For Ubuntu see [here](https://askubuntu.com/questions/15354/how-to-open-file-with-default-application-from-command-line). Maybe this works for other linux too. – ridgy Jun 09 '17 at 11:47
  • +1 `xdg-open` is part of the freedesktop [xdg-utils](https://www.freedesktop.org/wiki/Software/xdg-utils/) suite - so should be a bit more generic than just Ubuntu I think – steeldriver Jun 09 '17 at 11:49
  • You're right, thank you. See https://unix.stackexchange.com/questions/251054/how-does-the-xdg-open-command-know-which-application-to-use-to-open-a-file – ridgy Jun 09 '17 at 11:51
  • @steeldriver: Make that an answer so I can accept? – einpoklum Jun 09 '17 at 13:00

1 Answers1

3

For desktop environments that implement the freedesktop.org xdg-utils tools, you should be able to use xdg-open:

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.

xdg-open is for use inside a desktop session only. It is not recommended to use xdg-open as root.

Options

--help Show command synopsis.

--manual Show this manual page.

--version Show the xdg-utils version information.

steeldriver
  • 78,509
  • 12
  • 109
  • 152