This tutorial will explain how to open file from console with preferred application in Ubuntu, just like when double-click on a .mp3 file in nautilus, rhythmbox player launches and plays the music, also urls can be open with the default web browser from the terminal.
There’re following command tools do this work:
- gnome-open opens a file with Gnome’s default application
- kde-open opens a file with KDE’s default application
- xdg-open opens a file with X’s default application
I’m running on Ubuntu’s default Unity desktop, so I uses xdg-open or gnome-open:
For example, following command launches Rhythmbox and plays ‘tatu – stars.mp3′:
xdg-open /media/windisk/KuGou/tatu\ -\ stars.mp3
and this command will launch google chrome(in my case) and navigate to www.google.com:
Change Preferred Application from terminal:
You can use xdg-mime to check and change default app launcher.
- To check default app to read pdf:
xdg-mime query default application/pdf
it outputs something like this:
- To replace it with evince:
xdg-mime default evince.desktop application/pdf