APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed
RSS Feeds RSS Feeds











(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version
->
-> Aliases and links



Aliases and links




Aliases and links both allow you to create other names for the same file and even have those names in other directories. You can have "/Users/you/fred" and "/Users/you/desktop/stuff" be the same thing: edit either one and you'll see the changes in the other.

There are actually three forms of linking in Mac OS X: aliases, hard links, and symbolic links. These are all really file system features, but HFS+ supports all three, and for the example given above, all three are identical.

But there are differences. Hard links come over from the Unix world, and are simply directory entries pointing to the same inode. The inode is the traditional Unix metadata that has information about permissions, ownership and disk blocks used; if two directory entries point to the same inode, they are pointing to the same file. Technically HFS+ file systems don't have inode tables. However,just about everything works as though they did. See Usenix2000 invitedtalks sanchez_html/) and http://developer.apple.com/technotes/tn/tn1150.html (link dead, sorry) Apple.com technotes.

A hard link can't refer to a directory (because it would just be too easy to completely screw up the file system) and it can't refer to a file on another file system (because inode numbers are only unique to an individual file system).

A symbolic link is again from Unix, but is really just text that contains the path to another file. Its metadata is marked so that that path is interpreted rather than being seen as text. A symbolic link can refer to a directory, a file on a different file system, or even another symbolic link.

HOW that text is stored varies. It could be a specially marked file, but ,for example, HTFS (the most common filesystem on SCO Unix) stores symbolic links of up to 52 bytes in the inode. Longer symlinks are written into a filesystem block. EAFS/S51K filesystems always write into a disk block. I don't know how Mac OS X file systems specifically do this.

Aliases are a Mac invention, and are similar in concept to symbolic links, but don't depend upon the original path name to find the "real" file. It uses a "unique identity" instead. If you renamed or moved a file referenced by a symbolic link, the link would be broken and would not work, but an alias still would.

If you stay away from the command line, your Mac will always do the "right thing" with regard to aliases, but you can get confused if you mess with aliases in Terminal. You cannot "see" the original file with ordinary terminal commands; if "fred" is an alias for "tom", "cat fred" will come up empty. You can "vi fred", but whatever you put in there won't change "tom" in any way.

Interestingly, an alias does store path name information, apparently as redundancy: if the file can't be found from the unique identity, OS X (the file system driver, really) will try to find it by path name. There seems to be confusion in some documentation; http://developer.apple.com/documentation/MacOSX/Conceptual/BPFileSystem/Articles/Aliases.html (link dead, sorry) Apple documentation says:

 In versions of Mac OS X before 10.2, aliases located a file or folder
 using its unique identity first and its pathname second. Beginning with
 Mac OS X 10.2, aliases reversed this search order by using the pathname
 first and unique identity second. This means that if you move a file
 and replace it with an identically named file, aliases to the original
 file now point to the new file. Similarly, if you move a file on the
 same volume (without replacing it), aliases use the unique identify
 information to locate the file.
 
 When a file or folder moves, the alias may update either its path
 information or unique identify information to account for the change. If
 a file moves somewhere on the same volume, the alias updates its internal
 record with the new path information for the file. Similarly, if the
 original file is replaced by a file with the same name, but a different
 unique identity, the alias updates its internal record with the unique
 identity of the new file.
 
 

Note that the difficulties that come from moving with aliases are only confusing when moving the original to a different file system.




If this page was useful to you, please help others find it:  





3 comments




More Articles by - Find me on Google+



Click here to add your comments
- no registration needed!




Mon Feb 1 14:15:04 2010: 8015   SteveTheOcean

gravatar


I seem to remember there was an OS/2 feature that worked like aliases. I forget what is was called (let's call it xx here) but, like aliases, if you moved the underlying file to which it was referring xx would also be updated.

Also, as you say, directories can not be hard-linked in OSX. Dinosaur that I am, I seem to recall that you could do this on other versions of Unix, though it was not recommended. The file system can identify a soft link for what it is but it can't differentiate between hard links. This can lead to problems with programs (such as find) that travel down a directory tree.



Sat Jul 13 07:12:35 2013: 12223   Rumboogy

gravatar


Great article on aliases. But from my experience part of it is not accurate - at least not accurate now, perhaps it was in the past. The quote from Apple saying that if you move a file an alias pointing to that file is updated does not describe what really happens currently with OS X. Try it for yourself and see. Make an alias to a file then move the file. Then open the Info on the alias to see that it has the old path to the target file. You can also uses strings on the alias from the terminal to see the path in the alias.

This lack of updating of the alias causes problems when you migrate your data to a new disk. Each time I do a migration some percentage of my aliases stop working. Invariably they are the ones that have had their target's moved before the migration. So as long as an alias and its target are on their original disk/partition all is fine. But when I migrate that entire disk to another disk (using a bit-level copying like Disk Utility Restore), then the aliases who's internal paths are wrong don't work anymore. If there were a way to update/refresh these aliases before the migration then this would not be problem (which is what your quote from Apple documentation says is happening). But it is not happening, and I can't find a way to make it happen. So I have to manually fix aliases after each disk migration.






Sat Jul 13 10:01:07 2013: 12225   TonyLawrence

gravatar


Well, those links are long gone (I updated the article to reflect that), but I notice that you said you used bit level copying - I would expect that would NOT update the link (though you say "some percentage", which is confusing).

I just moved an aliased file with Finder and it worked as advertised. It's that "some percentage" that bothers me. Do you mean that if I had a pile of aliases and then bit-level copied to a new drive that some would work there and some wouldn't?









Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar

Kerio Samepage


Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

I am a Kerio reseller. Articles here related to Kerio products reflect my honest opinion, but I do have an obvious interest in selling those products also.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.

pavatar.jpg

This post tagged:

       - MacOSX















My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!


book graphic unix and linux troubleshooting guide



Buy Kerio from a dealer
who knows tech:
I sell and support

Kerio Connect Mail server, Control, Workspace and Operator licenses and subscription renewals



Click and enter your name and phone number to call me about Kerio® products right now (Flash required)