Terminal command to remove custom icon from file (HFS+)
For files with a custom icon, macOS writes the icon data as a resource fork to the file.  Use the xattr command in the following form:

xattr -d com.apple.ResourceFork /path/to/filename


For more information about the xattr command, in Terminal type the following command and press: enter

man xattr


Or just type xattr and then right-click on it and select: Open man Page



For folders with custom icon, in Terminal, change directory to the folder containing the custom icon, e.g.:

cd /path/to/foo


Once in the directory, use the following command to remove the custom icon:

rm Icon?


Note that you can also just use:

rm /path/to/foo/Icon?


However, you cannot use quotes, single or double, if the pathname has spaces and must escape the spaces with a backslash, \, e.g.:

rm /path/to/foo\ bar/Icon?


Quoting the pathname will just return the following error:

: No such file or directory


By default, Icon? is a hidden file and the ? in Icon? is actually a linefeed, \n, character.