Even though aliases and symbolic links may seem to be the same thing in Mac OS X, this is not completely true. One could think they are effectively the same because, with the switch to a Unix base in version 10.0, symbolic links became a "normal thing" in the system. However, for better or worse, differences still remain; let's see them.
Symbolic links can only be created from the command line by using the ln(1) utility. Once created, the Finder will represent them as aliases (with a little arrow in their icon's lower-left corner) and treat them as such. A symbolic link is stored on disk as a non-empty file which contains the full or relative path to the file it points to; then, the link's inode is marked as special by activating its symbolic link flag. (This is how things work in UFS; I suspect HFS+ is similar, but cannot confirm it.)
Aliases, on the other hand, are created from the Finder (and possibly with SetFile(1), but I don't know how) and are stored as regular, empty files if inspected from the command line. However, they have the a extended attribute set on them, which marks them as special files, and the necessary information is stored (I think) in their resource fork.
The interesting thing about aliases is that they are more versatile than symbolic links. For example: an alias can point to a file that is stored inside a disk image. When accessing such an alias, the system will automatically mount the corresponding disk image if not already mounted and then redirect you to the file. This may be interesting to transparently access files saved into an encrypted disk image: you store the files into the image, create aliases to them on your desktop and, when opened by any alias-aware application, the system will ask you for the image's password, mount it and provide you the file. But, unfortunately, aliases do not work from the command line, so this benefit is not as impressive as it could be (at least for me).
4 comments:
I was searching for "How do I use an alias from the command line" and ran across your post. You didn't have the answer, but I did find one hack later in my search. Basically, the hack is to use osascript (AppleScript) to find the correct path.
http://theapotek.com/2006/12/01/making-the-mac-os-x-bash-shell-alias-and-symlink-agnostic/>here
Very useful info - helped me a lot with a build issue I had. Thank you Julio.
to the previous anonymous post: please learn to read first and then comment
I found this post very useful. Thanks for the info!
I was mastering a CD ROM with an Alias on the root-level that points to a flash-application in a folder on the CD. When copied from CD to the Desktop, the copied alias points to the application on the CD. The CD ejected, the Alias-Dialog sais that it can not find the orignial. Because it doesn't find the CD-Volume anymore.
So I tried to use a symbolic link, that uses a relative path to make the connection to the orignial. Symbolic links work on HFS+, on UDF-DVDs, but they can't be used on a Hybrid-CD-ROM.
Solution:
Before Mastering, create an Alias of the original application. Make a copy of the original application. (same hierarchy) Delete the original Application an rename the copy with the original name. Test the alias. (Don't use the function to update the connection to the original!) The alias makes know the connection by a relative path. The structure can now be copied to a new place or volume and the alias always finds the copied original.
When the original file is deleted, the Alias looses the connection by the internal file-ID an replaces it trough the relative path. This hint helps distributing structures with Aliases by CD-ROM.
Post a Comment