I couldn’t find a built-in command-line program to set an icon for a file in OS X. Here’s a RubyCocoa script to do the job:
require 'osx/cocoa'
OSX.NSApplicationLoad
img = OSX::NSImage.alloc.initByReferencingFile("some.icns")
OSX::NSWorkspace.sharedWorkspace.setIcon_forFile_options(img, "foo.txt", 0)
previously: Wasting Valuable Pixels