How to Change USB Thumb icon using Terminal or Bash/other scripting language
You need to copy the .icns file to the root folder of the volume. The new file needs to be named .VolumeIcon.icns. For example, if you are using a Bash shell, have the file vol_external.icns and destination /Volumes/MyStick, then below would be the command.

cp  vol_external.icns  /Volumes/MyStick/.VolumeIcon.icns



  A word of warning: Once you assign an icon to a volume,  changing this icon is very difficult. I feel there must be a bug somewhere in OS X. However, deleting the icon does seem to work.


To get a directory listing for this copied file, you may need to include the -a option in the ls command line. For example, the command

ls  /Volumes/MyStick


will not display the file .VolumeIcon.icns, but the command

ls  -a  /Volumes/MyStick


will show the file.


  Note: Normally, files starting with a . do not appear in the Finder application.