How do I change the icon for a particular file type?

I'm trying to change the icon for application/x-hwp files. I've added the icons to the proper places, and checked it with assoGiate (after reading this thread). It shows that my desired icon is associated with the file type. Nevertheless, Nautilus is still showing the old icon. How can I make Nautilus show the correct icon?


Here is a set of instructions that should get you a custom icon for hwp files.

Open a terminal :

  • Check the MIME type exists : grep 'hwp' /etc/mime.types

    if you get an output resembling application/x-hwp hwp skip the next step.

  • Create the MIME type sudo -H gedit /etc/mime.types and add the line application/x-hwp hwp

  • Add the icon (which must be called application-x-hwp.svg):

    sudo cp PathToIcon/application-x-hwp.svg /usr/share/icons/gnome/scalable/mimetypes
    

    (don't forget to replace PathToIcon)

Got the information from here


The main trick is to find out correctly where the actual icons are located.
In order to determine that let's analyze HTML icons. Naming convention for the icons is the same as for the MIME-type, only / is replaced with - and no capital letters are allowed. I.e. MIME-type, say, text/x-changelog will have the icon named text-x-changelog.svg (or png). MIME-type for HTML is text/html. So its icon will be text-html.* If we run the command

find /usr/share/icons/ -type f | grep 'text-html\.'

we will get several places where these icons are placed:

/usr/share/icons/Humanity/mimes/
/usr/share/icons/gnome/NNxNN/mimetypes/
/usr/share/icons/HighContrast/scalable/mimetypes/

If we visit each of them with Nautilus we'll see, that Humanity/ folder contains our current icons, gnome/ - some older ones. HighContrast/ doesn't interest us. So in order to change some icon we should replace the icons located in Humanity/ folder.
Also notice that text-html.svg icons which are scalable and should have been placed into scalable subfolder (that should be logical) are placed into the folders for different sizes instead, in the same way as raster PNG files.

After replace of the icons (in all subfolders according to their sizes) with the desired ones icon cache should be updated:

sudo gtk-update-icon-cache /usr/share/icons/Humanity

That's it.

There's another way to determine the precedence of icon schemes - to check their index.theme files. If we look inside /usr/share/icons/Humanity/index.theme, we'll see:

Inherits=gnome,hicolor

This means that icons from gnome and hicolor folders will have less precedence than the ones from Humanity. This is explained here.
Strangely enough, Nautilus doesn't obey these inheritance rules. When I added new MIME-type, I tried placing its icons into /usr/share/icons/gnome/, /usr/share/icons/hicolor, ~/.local/share/icons/hicolor, updating icon database on each step - all in vain. These icons were displayed properly in assogiate on the first tab, but never in Nautilus. But when I placed them into Humanity folder and updated icon database, they appeared at once.

N.B. All this applies to the default icon theme. If you use some custom icon theme, you should check where the actual icons are located and add/change icons there instead. Also in newer distributions these inheritance rules may change. Then you should locate the new folder which stores the actual icons (if it is not Humanity anymore) as explained previously.