How can I change the folder icon in Nautilus with a command?

Solution 1:

If you want to change the special folder icons (xdg user directories), you'll have to change them by making a custom theme. They are set to a specific name which is provided by the theme, and based on which folders are set as your Music, Documents, Videos, etc… folders.

To set a custom icon name to use from the theme, for the ~/.wine/drive_c folder for example, you can run the following in a terminal:

gvfs-set-attribute ~/.wine/drive_c metadata::custom-icon-name folder-wine

This should make Nautilus use the folder-wine icon. However, this icon will not be used in GTK+ file selectors or other applications. To unset the custom icon name, you can run the following in a terminal:

gvfs-set-attribute -t unset ~/.wine/drive_c metadata::custom-icon-name folder-wine

Note, that if you've previously set a custom icon on the file, within Nautilus directly, you'll have to unset that icon. You can do this by opening the properties dialog for that file in Nautilus, clicking on the button with the icon on it, and choosing "Revert" in the file chooser dialog which opens up.