`xdg-open` does not open files in the preferred applicaton

xdg-open does not work as expected. It opens most my files in browser, directories in my code editor(VS code) and plain text files using less. It also throws this error message,

$ xdg-open $HOME
xdg-mime: mimetype argument missing
Try 'xdg-mime --help' for more information.

then it opens the folder in my code editor. Whereas,

$ xdg-mime query default inode/directory

the default file manager application is Nautilus. How do I fix this?

Asked By: Akash Karnatak


The following answer suggests that Gnome uses gvfs-open in the background.


gvfs-open has been deprecated and the new command is gio open.

$ gio open
libffi.so.6: cannot open shared object file: No such file or directory

Running gio open threw this error. This error was due to python looking for libffi6.so file which wasn’t present in my environment. I am using miniconda and there are other people as well who are facing this issue. Most of the answers suggests to create a symlink for libffi6.so or reinstall python,



But simply installing libffi, using conda fixed the issue.

conda install libffi

Answered By: Akash Karnatak

the xdg-mime is unable to determine the appropriate application to use to open the file. This can cause xdg-open to open files in the wrong application.

  1. Check the default applications: Run the command xdg-mime query default <mimetype> to check the default application associated with the specific mimetype. For example, xdg-mime query default inode/directory will show the default file manager application.

  2. Set the default application: If the default application is not set or incorrect, you can set it using the command xdg-mime default <application.desktop> <mimetype>. For example, to set Nautilus as the default file manager, run xdg-mime default org.gnome.Nautilus.desktop inode/directory.

After following these steps, xdg-open should be able to open files in the preferred application.

Answered By: benHaseep