Debian LibreOffice Defaults – Setting Default Application for Filetypes via CLI

debiandefaultsfile-typeslibreofficemime-types

I have 150 Debian Jessie machines that open ODS files in Gnumeric when double-clicked despite LibreOffice Calc being installed. I know it is possible to change this by right-clicking the ODS file and changing its default program from the Properties window, but getting 150 users to do this is not an option. They all use xfce4 and thunar.

I need to do this via CLI so I can do it across all workstations remotely. I have looked in /usr/share/applications and ~/.local/share/application/mimetypes.list with no luck – comparing the files before and after changing it via GUI revealed no changes here.

How can I use bash to make these workstations open ODS files with LibreOffice Calc by default?

EDIT: Unlike the answers to this question, my Jessie installs do not have ~/.config/mimeapps.list or /usr/share/applications/defaults.list

Best Answer

You can use mimeopen with -d option:

man mimeopen :

DESCRIPTION
   This script tries to determine the mimetype of a file and open it with
   the default desktop application. If no default application is
   configured the user is prompted with an "open with" menu in the
   terminal.


-d, --ask-default
       Let the user choose a new default program for given files.

Example:

mimeopen -d file.mp4

sample output:

Please choose a default application for files of type video/mp4

   1) VLC media player  (vlc)
   2) Other...

Verify it:

xdg-open file.mp4
Related Question