How can I open a file in my terminal, like nautilus does it? [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