If a file tells the OS its file format, how does the OS choose which application to open it by default?
In Windows, is the association stored in the registry table?
How does Linux choose which application to open a file?
I used to use Nautilus a lot, but now I change to terminal. Is it true that in terminal, we always have to explicitly specify which application to open a file? Does the settings of which application to open a file of a certain format by default belong to the file manager (e.g. Nautilus), and it is not an issue when we are living in terminals?
Best Answer
There may be different mechanisms to handle these default settings. However, other answers tend to focus on complete desktop environments, each of them with its own mechanism. Yet, these are not always installed on a system (I use OpenBox a lot), and in this case, tools such as
xdg-open
may be used.Quoting the Arch Wiki:
At this moment, I am using Ubuntu (12.04) and
xdg-open
is available. However, when you use a complete desktop environment such as GNOME,xdg-open
acts as a simple forwarder, and relays the file requests to your DE, which is then free to handle it as it wants (see other answers for GNOME and Nautilus, for instance).... which brings you back to the other answers in that case. Still, since this is Unix & Linux, and not Ask Ubuntu:
All in all:
If the first case, you'll need to configure
xdg-open
directly, using thexdg-mime
command (which will also allow you to see which application is supposed to handle which file). In the second case...... you'll need to configure the file-opener associated with your desktop environment. In some cases, configuration made through
xdg-mime
may be redirected to the proper configuration tool in your environment.