Radu
Radu

Reputation: 973

Opening a file with the default viewer on Linux

I am working at an OS independent file manager (mostly Windows and Linux), and I am wondering if there is a Linux way to open a file in its default viewer. For example, open a html file with Firefox, an .avi with vlc, and so on. On Windows, there is a function ShellExecute() that does that, but my understanding is that on Linux it is not that simple, and each desktop environment has a specific way. I would appreciate any help with this.

Upvotes: 5

Views: 533

Answers (4)

O.C.
O.C.

Reputation: 6819

Sahil Muthoo has given you good advice. I will just give further examples.

If xdg-open is not available you can also use "gnome-open" for GNOME and "kfmclient" for KDE.

Upvotes: 0

thiton
thiton

Reputation: 36049

The default programs for different mime-types are defined in /etc/mailcap and $HOME/.mailcap, indexed by file type and action (display, edit, print). The command line interface is run-mailcap. See also the manpages run-mailcap(1) and mailcap(5).

Upvotes: 2

Sahil Muthoo
Sahil Muthoo

Reputation: 12519

You could use xdg-open(1). It works on all freedesktop compliant desktops.

Upvotes: 10

It depends what desktop environment you're using in Linux. Gnome for example has a MIME database you can use to find out what to launch for a given file.

Upvotes: 1

Related Questions