Read more

Linux: Open a file with the default application

Henning Koch
March 02, 2016Software engineer at makandra GmbH

If you are on a Linux shell and want to open a file with whatever default application is configured for that type, this often works:

xdg-open Quote.odt
xdg-open invoice.pdf
xdg-open index.html

Pro Tip

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

Make an alias so you have a simpler API (like Mac OS): alias open=xdg-open or alias x=xdg-open.

Background

You can choose your "Default applications" via UI in the Ubuntu "Settings" application (gnome-control-center). This is just a very rough setting (e.g. open Photos with Shotwell Viewer).

If a certain file type (or better mime type) should be opened with a different application, this can be set via command line:

# Query the default application:
xdg-mime query default $(xdg-mime query filetype <file>)

# Override the default application for this filetype with:
mimeopen -Dd <file>

Changed mime default are stored in ~/.config/mimeapps.list (and sometimes ~/.config/*-mimeapps.list).

Further reading

Posted by Henning Koch to makandra dev (2016-03-02 15:37)