Understanding file associations in LXDE and PCManFM

Or “understanding how PCManFM decides which program to launch when you double-click on a file”

Or “understanding the list of suggested programs when you right-click on a file in PCManFM”

Or “making sense of the mimeinfo.cache, defaults.list and mimeapps.list crazyness”

The problem

Create a text file (text.txt) file in PCManFM and right click on it: PCManFM displays a list of possible application that can open the file:

Now if I double-click on the text.txt file, abiword (the first item highlighted in the screenshot above) is going to be launched.

  • Where does this “AbiWord – gedit- Leafpad” list come from ?
  • I want to use gedit instead of AbiWord when double-clicking on the file: how can I change this ?
  • I want my text file to be opened by a program that is not listed: how can I do this ?
  • Where in the world is Carmen SanDiego ?

Sit back and relax, I’m going to tell you the whole story.

At the beginning, there was the .desktop files

These files are mainly used to specify which elements are going to be displayed in the LXDE start menu and on your desktop. Check my creating LXDE shortcuts post for more information.

Then there was mimeinfo.cache

This file is located in /usr/share/applications/mimeinfo.cache and it is a basically a raw reverse cache for the .desktop information. Check this link for more information.

More precisely, each .desktop file on your system (which can be located either in /usr/share/applications, in /usr/local/share/applications or in ~/.local/share/applications) can contain a “MimeType” attribute which states the mimetype that the program associated to the .desktop file can handle.

On my Fedora installation, I have 3 text editors: Abiword, Leafpad and gedit and each one of them can open files that have a text/plain mimetype:

[laurent@localhost applications]$ cat fedora-abiword.desktop | grep text/plain

[laurent@localhost applications]$ cat gedit.desktop | grep text/plain

[laurent@localhost applications]$ cat fedora-leafpad.desktop | grep text/plain

Now if I have a look in mimeinfo.cache, I can find the reverse mapping that we just talked about:

[laurent@localhost applications]$ cat mimeinfo.cache | grep text/plain

So this translates to “any file with a text/plain mimetype can be opened using either abiword, gedit or leafpad”.

Astute readers will notice that:

  • This list (abiword + gedit + leafpad) is exactly the one displayed in PCManFM when I right click on a file (see screenshot above).
  • The first item in this list (in my case: abiword) is the program that is launched when I double-click on a text file in PCManFM.

However, editing this mimecache.info file (to change the order of the .desktop files that are associated with the text/plain mimetype) is not what you want to do. The truth is you may lose all your changes after installing/removing a new Linux package.

This is because this file is generated by launching the “update-desktop-database” utility. This tool parses all your .desktop files and generates the mimeinfo.cache file… more or less each time you install a new package. This is where the defaults.list files join the party

Here comes defaults.list

defaults.list is a file where you configure the default program that should be used to open a file. To be very specific, this is where you configure the default “mime type -> .desktop file” association.

Like .desktop files, you can have a defaults.list file in any of the following locations (you can even have 3 files: one at each location).

  • /usr/share/applications
  • /usr/local/share/applications
  • ~/.local/share/applications

First, there is a global defaults.list file located in /usr/share/applications and then you can have one for each user, located in ~/.local/share/applications. As you can guess, the “user-level” file has higher priority than the “global one”.

If I only have a /usr/share/applications/defaults.list file that contains a “text/plain -> gedit.desktop” mapping, then double-clicking on a text file in PCManFM will open gedit, no matter what the ordering of mimeinfo.cache is:

[laurent@localhost applications]$ cat /usr/share/applications/defaults.list | grep text/plain

But if I also have a ~/.local/share/applications/default.list file that contains a “text/plain -> fedora-leafpad.desktop” mapping, then double-clicking on a text file in PCManFM will open leafpad (since this file has “higher priority” than the files in the 2 other locations).

[laurent@localhost applications]$ cat ~/.local/share/applications/defaults.list | grep text/plain

But wait, there is more !

The mimeinfo.cache, the defaults.list and the mimeapps.list

Yes that’s true, one more file to bother you (did I mention “crazyness” at the beginning of this post ?).

Now if you think that ~/.local/share/applications/defaults.list has higher priority than /usr/share/applications/defaults.list which has higher priority than /usr/share/applications/mimeinfo.cache”, you would still be incorrect because ~/.local/share/applications/mimeapps.list has even higher priority than all these bastards.

mimeapps.list allows you to:

  • add even more “right-click” options to PCManFM right click menu
  • set the default program for a mimetype (exactly like in defaults.list)

Although I’m not aware of any tool to help you deal with defaults.list file, there are at least 2 options to help you with mimeapps.list

OK, so let’s say that you would like to open your text file with yet another program that is not listed in the PCManFM right-click menu. Just choose the “Open with…” option and select an application. In my case, I’ll choose “Xpad”, and I’ll choose the “set selected application as default” option:

And there you are, xpad is now part of your right-click menu:

Behind the scene, PCManFM created a mimeapps.list file:

laurent@localhost applications]$ cat ~/.local/share/applications/mimeapps.list

[Added Associations]

[Default Applications]


Another way to generate this file is to use the xdg-mime tool with “xdg-mime default fedora-xpad.desktop text/plain”

So let’s recap

The list of program that is displayed when right-clicking on a file in PCManFM is the combination of:

  • mimeinfo.cache
  • mimeapps.list

The default program that is launched when you double-click on a file in PCManFM is (first match wins):

  • The one from ~/.local/share/applications/mimeapps.list
  • The one from ~/.local/share/applications/defaults.list
  • The one from /usr/local/share/applications/defaults.list
  • The one from /usr/share/applications/defaults.list
  • The first one from /usr/share/applications/mimeinfo.cache



About lkubaski

10 Responses to Understanding file associations in LXDE and PCManFM

  1. Cor says:

    Very well explained, thanks!

  2. Maurício says:

    hi !

    i use lubuntu, and i have a problem:
    with pcmanfm, howto i open selected files (example: multiple video files, or multiple text files) ?

    when i select multiple files, and hit , pcmanfm opens only the last on the selected list.
    maybe a shortcut key ?
    can you help me ?

    anyway, thanks for attention !
    (sorry my english…)

    from Brazil

  3. shan says:

    cool info

    really go to

    gedit ~/.local/share/applications/mimeapps.list

    and change there and all will follow

  4. mhtrinh says:

    Thank you very much !!!

    This kind of information is never documented on the package’s doc/wiki sadly 😦
    And I Iike those lines that you put in the begining of the post so that even if we search with a different sentence, we still have chance to end up here ! Good job buddy !!!

  5. Am says:

    Thank you a lot for this article ( too 🙂 )

  6. Daro says:

    Great job!

  7. deevad says:

    Thank you for the article, I’m reading it four years after the publishing and the mimeinfo.cache, defaults.list and mimeapps.list crazyness is still around in Ubuntu or Arch. Now I understand how to apply local fix to the issues I had with my ‘open with’ list. 🙂

  8. Pingback: Understanding file associations in LXDE and PCManFM | The skiing cube - dowe.io

  9. Carlos Vega says:

    I can’t express enough how useful this post was for me. Thx so much!

  10. Ryan says:

    ~/.local/share/applications/mimeapps.list seems to be obsolete, PCManFM now writes to ~/.config/mimeapps.list

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: