Ubuntu – How to open a file in the terminal, like nautilus does it?


I want to be able to open files like my operating system does from console.

e.g. a .pdf file should be opened with evince or whatever the default application to open pdfs is. All the other things should work too; images -> eog, text files -> gedit and so on.

I hope that there is a solution for this, it would be really practical.

Best Answer

xdg-open — opens a file or URL in the user's preferred application

But what if you want to change the preferred application from the terminal?

Try this

You can use the xdg-mime program to first check which is the current default application that will open a file and then you can switch it to what ever application you want.

$ xdg-mime query default application/pdf
$ xdg-mime default evince.desktop application/pdf
$ xdg-mime query default application/pdf

Now as mentioned by jokerdino you can use xdg-open to open a file with your preferred application:

$ xdg-open file.pdf
Related Question