0

If I have a mime type of a file using the command line file -bi.

How do I get the associated icon of this mime type from the current appearance icons theme?

Thank you everyone.

6
  • If your DE is GNOME just run gio info -a standard::icon PATH Jan 26, 2018 at 18:40
  • thank you @don_crissti . but i have the mime type only, and i want the associated icon to it. i don't have a file path.
    – Bilux
    Jan 26, 2018 at 19:29
  • You have the mime type only ? Then why did you write "If I have a mime type of a file using the command line : 'file -bi'" ? That command works only if you use a file name (file path) as argument so how do you have only the mime type ? Jan 26, 2018 at 20:03
  • @don_crissti i just wanted to make things clear. i intend to use specific mime type from java code, and extract the associated icon to it.
    – Bilux
    Jan 26, 2018 at 20:35
  • You've confused things. Please don't invent information that isn't relevant. Do you mean to write, "If I have a mime type how do I get its associated icon from the current appearance icons theme?"
    – roaima
    Jan 27, 2018 at 22:26

1 Answer 1

1

The Freedesktop.org Shared MIME Type Specification would be the applicable standard.

In short, search for the MIME type in /usr/share/mime/icons and /usr/share/mime/generic-icons files. If it's in there, the file tells you the name of the icon file. The first file contains icon names with exact matches to a particular MIME type; the second maps MIME types to generic icons in case there is no exactly matching icon for the file type. If there is still no hits, there are 16 or so standard icon names for generic file type icons, defined in Icon Naming Specification.

Now you know the basename of the icon. The actual icon file can be found within the /usr/share/icons/<theme name>/<icon size>/mimetypes/ directory.

How to know the <theme name> part? Well, that still depends on which desktop environment you're using.

For the environments using the gtk toolkit, use:

gsettings get org.gnome.desktop.interface icon-theme

or for older versions:

gconftool-2 --get "/desktop/gnome/interface/icon_theme"

For KDE5, use:

kreadconfig5 --group Icons --key Theme

For older versions of KDE, drop the 5.

For XFCE specifically, this would seem to be the command to query the icon theme name:

xfconf-query -c xsettings -p /Net/IconThemeName

Note: at the time of this writing, the Shared MIME Type Specification is still pretty new, and there may be Linux distributions that don't yet follow it. In that case, this webpage may be helpful.

2
  • thank you very much for the wonderful explanation. I'm using XFCE desktop environment.
    – Bilux
    Jan 27, 2018 at 10:11
  • XFCE specifics added to my answer.
    – telcoM
    Jan 27, 2018 at 13:33

Not the answer you're looking for? Browse other questions tagged .