Open any file using terminal window [duplicate]

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
AdobeReader.desktop
$ xdg-mime default evince.desktop application/pdf
$ xdg-mime query default application/pdf
evince.desktop

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

$ xdg-open file.pdf

  • 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

Well if you mean command with what you can open everything, it will choose automatically, there is gnome-open

If you want to open .pdf or whatever file it is, just type:

gnome-open blah.pdf

And there is xdg-open for this kinda works. What it does: it just looks what is default application for such type of files, and runs that app.

In manual of xdg-open

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

Also from here

xdg-open is part of the xdg-utils package available in [extra]. xdg-open is for use inside a desktop session only. It is not recommended to use xdg-open as root.

And sure to change "default" application, you will need xdg-mime
Example to change default pdf viewer:

$ xdg-mime default xpdf.desktop application/pdf

Source: https://wiki.archlinux.org/index.php/Xdg-open


To add to the existing points.

I find this command so important that I have an alias in ~/.bashrc:

alias go='xdg-open'

I also find the command xdg-open . or with the alias go . really useful. The period represents the working directory, and it opens Nautilus in the working directory. Thus, if you need to temporarily take advantage of features in Nautilus, such as opening files in alternate programs, deleting files with strange names, selecting strange combinations of files, etc. then you can do that in a relatively simple way.


You can use xdg-open, it should open a file with the default program:

xdg-open somename.pdf

will open somename with your default pdf reader.

Or, usually, you can just use the program name followed by the name (or path and name) of the file that you wish to open

evince somename.pdf

will open somename in evince.

If you want to be able to keep using the terminal while working with the file you can add & at the end of the command, it will be executed in the background and you can continue tying commands in the terminal. Otherwise you can't use the terminal until the program is closed.

xdg-open somename.pdf &