How to find the default file manager?

31,447

Solution 1

There is no such thing as a "Default File Manager for Linux". It all depends how you might be trying to open one. If you ask XDG, then you'll have to check what XDG thinks this file manager should be. Same deal for any other "environment", such as Gnome, or KDE. If you have all of them installed, it's perfectly possible (and fine) for each of them to have a different "default file manager".

The case for default apps seems to come mainly from Windows. Over there, we only have one environment, the one Windows presents us with. As such, the notion of a default application is indeed effectively system wide. This is not the case with Linux.

What you might perceive as default apps under Linux, such as what is stored in the $EDITOR environment variable, is not as much a "true" default app, as simply a convention used by a lot of people who write system tools and scripts. Feel free to define $FILEMANAGER, if that suits your use case.

Solution 2

Use the xdg-mime command to this. xdg should be desktop-environment agnostic (eg xdg-open will pass the arguments on to the correct file opener). To get the default file manager use:

xdg-mime query default inode/directory

Source

Solution 3

You can use xdg-open <DIR> to launch the file manager on a directory. You might be able to query some xdg application to find out what file manager is used.

Solution 4

Wow, unbelievable that nobody postet the correct answer here.

Default applications on Linux are handled by the Freedesktop (former XDG) Mimeapps Standard and several other specs that this one is based on.

The Arch Linux Wiki contains a comprehensible article too. What you are looking for is the association of the mimetype inode/directory.

Solution 5

Seems everybody mentioned the inode/directory MIME-type and the xdg-open should works in most of the cases for your need (programmatically open a directory via a file manager), but sometimes wrong application (which is not a file manager, e.g. Visual Studio Code) can also associate it with the inode/directory as the default application.

In addition there is also a file-manager-interface for D-Bus (org.freedesktop.FileManager1 in Session Bus) which can be used for your requirement so you can also use this if your file manager support this D-Bus interface. Please make sure if you can use it since not all file manager implemented this, currently it seems Dolphin (KDE), Nautilus (GNOME) and Deepin File Manager (DDE) implemented this D-Bus interface. And to find out which process owner this D-Bus interface (you don't need to do it if you just would like to request a path to be opened via a file manager programmatically), see this answer

Share:
31,447

Related videos on Youtube

Mauren
Author by

Mauren

Experienced software engineer, with a strong background in Java development.

Updated on September 18, 2022

Comments

  • Mauren
    Mauren over 1 year

    as a Linux user, I see that some applications can request a path to be opened and this causes a file manager to be launched. I'd like to do this programmatically, but how can I know which is the default file manager? Is there a way to find this info? Any environment variable? By "file manager", I mean applications that allow you to administer your files: create, rename, create folders, etc., like Nautilus (in GNOME) or Dolphin (in KDE).

    Thanks in advance!

  • Mauren
    Mauren almost 12 years
    I was thinking there might be an environment variable for this, and actually thought about defining one. Nice answer, thank you very much.
  • Mauren
    Mauren almost 12 years
    Thanks for the hint. I will try to use this to solve my problem.
  • Gerhard Burger
    Gerhard Burger about 10 years
    I think you mean XFCE instead of XDG?
  • mkaito
    mkaito about 10 years
  • Colin Keenan
    Colin Keenan about 7 years
    Thanks for this. I use Arch & should've thought to check the wiki, but didn't.
  • Gerhard Burger
    Gerhard Burger over 6 years
    And how is my answer not correct? I posted the exact command to query the inode/directory association with an xdg-mime query...
  • crypdick
    crypdick almost 6 years
    This should be the correct answer.
  • smac89
    smac89 about 4 years
    This is what I came looking for. After applying all the tricks with xdg-mime and mimeo, turns, out something else was at work and this was dbus filemanager. A quick look with d-feet reveals that the thunar file manager is registered in xfce using dbus. Now on to finding a way to replace that