Ubuntu – How to change the icons of many folders


I have a collection of films on my computer and every film is stored in its own folder with image of its cover.

What I would like to do is to change icon of each folder to icon of film's cover. Is there any way to do this quicker than right-clicking on each folder and changing icons manually?

Best Answer

You can do this from the command line:

gvfs-set-attribute -t string <directory> metadata::custom-icon file://<icon-location>

replacing <directory> with the name of the directory you want a custom icon for and <icon-location> with the location of the icon. For example, to change the icon of ~/Documents to a red apple:

gvfs-set-attribute -t string ~/Documents metadata::custom-icon file:///usr/share/pixmaps/apple-red.png

Now, to automate the process a bit, say that you have a directory ~/Videos/Films inside which you have one directory per film, each of which containing a file called icon.png that contains the desired icon. In that case you can type at the command line:

{ while read -r d ; do [ -d "$d" ] && [ -e "$d/icon.png" ] || continue ; gvfs-set-attribute -t string "$d" metadata::custom-icon "file://$d/icon.png" ; done ; } < <(find ~/Videos/Films -mindepth 1 -maxdepth 1 -type d)

Notice that an open nautilus window will need to be refreshed in order for any icon changes performed on the command line to take effect.