Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When I ls my Desktop from terminal (by using ls ~/Dekstop), I see a file, Icon?. As far as I can tell, it's empty (nano Icon? shows nothing). It doesn't show up on my actual Desktop, and open Icon? shows the Finder alert

This item is used by Mac OS X and can't be opened

Here is the output from mdls Icon?:

kMDItemContentType         = ""
kMDItemFSContentChangeDate = 2009-09-23 13:32:52 -0600
kMDItemFSCreationDate      = 2009-09-20 07:27:46 -0600
kMDItemFSCreatorCode       = "MACS"
kMDItemFSFinderFlags       = 16384
kMDItemFSHasCustomIcon     = 0
kMDItemFSInvisible         = 1
kMDItemFSIsExtensionHidden = 0
kMDItemFSIsStationery      = 0
kMDItemFSLabel             = 0
kMDItemFSName              = "Icon "
kMDItemFSNodeCount         = 0
kMDItemFSOwnerGroupID      = 20
kMDItemFSOwnerUserID       = 501
kMDItemFSSize              = 0
kMDItemFSTypeCode          = "icon"

Does anyone have an idea as to what this is?

share|improve this question
    
+1 - I've often wondered about this too. –  boehj Jun 18 '11 at 3:58

2 Answers 2

up vote 41 down vote accepted

What is it?

It's name is actually Icon\r, with \r being the carriage return 0x0D. If letting the shell autocomplete the path in Terminal, it yields Icon^M, ^M being \r.

Icon^M is a file existing in all directories that have a custom icon in Finder. If you change a directory's icon e.g. in its Get Info dialog by pasting an image into the icon in the upper left corner, the Icon^M file is created.

Changing a volume's icon creates a hidden .VolumeIcon.icns file instead.

Why is it invisible?

It's invisible in Finder, because its hidden attribute is set.

$ ls -lO Icon^M 
-rw-r--r--@ 1 danielbeck  staff  hidden 0 24 Apr 23:29 Icon?

Change with chflags nohidden Icon^M.

Where is its data?

While the file's data fork (i.e. content) is empty (i.e. a file size of 0 bytes in Terminal), the actual icon data is stored in the file's resource fork.

$ ls -l@ Icon^M
    com.apple.ResourceFork  350895 

You can copy the resource fork to a file (to view e.g. in a hex editor) like this:

$ cp Icon^M/..namedfork/rsrc Icondata

 How can I view it?

The easiest way to get the image is to copy the icon from the Get Info dialog of the folder it's contained in into the clipboard, and then create a new image from clipboard in Preview (Cmd-N). It's an icns image then by default.

Its format is JPEG 2000 according to the Mac OS version of XnView and you should be able to open it with that program. It doesn't seem to work with other programs that should support JPEG 2000, so this format information is probably wrong.

share|improve this answer
    
2  
Apple actually do this hiding of their data in a resource fork quite frequently. I can never decide if it's neat or misleading. –  Lukasa Jun 18 '11 at 10:10
    
It's consistent. Icons after all are resource fork contents. –  JdeBP Jun 18 '11 at 11:21
3  
You miss the wood for a single tree, grasshopper. Look beyond a volume icon file to the great forest of cases where, traditionally in MacOS at least, icons are to be found in resource forks. If you're trying to be all modern and hip and we-don't-need-no-steenking-resource-forks-we're-Unix-now, you should really correct your answer to use the modern and hip /..namedfork/rsrc suffix instead of the one that generates a warning message. (-: –  JdeBP Jun 18 '11 at 17:58
1  
My amazing psychic powers tell me that all of these printfs go to the system log. –  JdeBP Jun 19 '11 at 0:47

An Icon? file inside a directory contains a custom icon image for that directory. The image itself is stored inside an extended file attribute, specifically, com.apple.ResourceFork, which is why the Icon? file appears to have no length.

You can retrieve that data with $ xattr -p com.apple.ResourceFork Icon? or view all extended attributes with $ xattr -l Icon?

On Snow Leopard, at least, they appear to have been phased out for system icons (In the case of ~/Desktop/, that icon would be visible when viewing your home directory in icon view.) but for the two custom directory icons I have on my system, it still exists.

share|improve this answer
    
The "system icons" have never created an Icon^M file as far as I know. Rename these special folders with custom icons (easiest to do with ~/Applications, as it doesn't exist by default anyway) and their icon will change with it. –  Daniel Beck Jun 18 '11 at 4:45
    
@Daniel Yup; I suppose OP has a customized icon for his Desktop folder, then. –  NReilingh Jun 18 '11 at 4:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.