Steve's Pad

Aliases, symbolic links, Path Finder aliases… Help!

April 30, 2007

Today I want to write about something that confused me once and I was glad to find the explanation afterwards. I hope it will be useful for you as well. So here we go about the difference between aliases, symbolic links and Path Finder aliases.

Look similar...

Aliases and symbolic links (or symlinks) are "pointers" to a file or a folder which can be placed at a specific location while it is pointing to the "original" object at another location. You basically create a second representation of the object without having to create a copy.

Aliases are files that uniquely point to a specific file or directory, and continue to point to it regardless of where the file or directory (or the alias file itself) is moved or renamed. When an alias doesn't resolve, the system goes looking for it and asks you what it should do if it can't find it. Aliases are understood by the Finder, Path Finder and any other OS X program that implements the routines to resolve aliases.

Symbolic links are very similar to aliases, but symbolic links are lower level. They belong to the file system itself, and thus can be parsed by your terminal shell. Most Unix-level commands and utilities do not understand aliases, so it is necessary to use symbolic links if the file or folder will be accessed from a Unix-level program (e.g. Apache). Programs of higher level, like Finder or Path Finder have no problems to resolve symbolic links, so symlinks are understood throughout the whole system.

...but are different

An important difference between an alias and a symlink is that if the original file is moved or renamed and a file with the same name is put at the former place, an alias will still point to the previous version of the file, while a symbolic link will point to the new file at the same place. This behavior is useful e.g. when you need a reference to a file or a folder which is replaced in regular intervals by new versions, while the previous versions are archived. However a disadvantage of a symlink is that when it doesn't resolve it just goes broken. (it happens because symlinks are just files containing a string with the path to the file, whereas aliases store their information in resource fork thus containing more information about the original)

Both symbolic links and aliases are useful. Sometimes you want to point to a particular file or directory in a robust manner that will not break when things are moved or renamed (alias), but sometimes you simply want to point to "whatever file happens to be located at the following path..." (symlink). So the decision to use one or another depends on what you want to do with your original and what programs are supposed to access the link.

Although symbolic links are a core feature of Mac OS X, Finder is unable to create them. Also there is no easy way to distinguish an alias from a symbolic link in Finder. Both aliases and symbolic links appear in Finder with a little arrow in their icons. If you use "Get Info" in Finder on a symbolic link, it will show its kind as "Alias" - which is a bit misleading at least. Path Finder knows how to distinguish between symlinks and aliases, displaying their kind correctly and can also create them sparing you a trip to terminal.

GetInfo

Now what are Path Finder aliases?

Path Finder aliases are like regular aliases but that only Path Finder understands. They will always open the original in Path Finder regardless of the program you use to open them. They are actually just special files (with a hidden extension .path) that PF knows how to open, their kind is "Path Finder document".

What are they useful for?

Suppose you would like to have a folder in the Dock which would open in Path Finder. You can create a Path Finder alias (go to menu File -> Make Path Finder alias) of this folder and put it in the Dock - it will then always open in Path Finder instead of Finder. Handy, huh?

---------

Update: one of the commenters reminded me about hard links and I thought I'll complete my explanation although hard links are only rarely used on OS X.

Hard links - beasts from the past

Hard links act like "twins" in sync, you can't even tell which is the link and which is the original actually (Get Info on both files will show exactly same type of document, same size, etc). For example you change permissions on one file - and it automatically changes it on the other one, you can't even delete the file completely without deleting the other. On OS X Tiger it's not possible to make a hard link to a directory, only to a file (update: this is no longer true on Leopard, Time Machine uses hard links to folders), also your hard link should be located on the same partition of your drive as the original.

As far as I know, hard links are not always well supported by high level OS X apps, probably because in a certain way they are even lower level than symbolic links. If you allow me to go to really low level details, hard links are direct "pointers" to a unique identifier - a file system object called "inode" - which describes where all the pieces of a file are as well as various other attributes such as last access, modified and create times. When the file is written to the disk, blocks of data containing the file are given this unique identifier (inode) so that your filesystem knows that "file #000234" is the data starting at disk block #00FF and ending at ##0145. Now consider the following: aliases store the path *and* this unique identifier in their resource fork (thus knowing about the physical location of the original on disk regardless of it's path and vice a versa), symlinks store only the path to the file and hard links store only the unique identifier, thus all those differences in their behaviour. To add some history (and I'll stop there, it's getting terribly long now) - hard links have been around since the earliest days of Unix, symbolic links were invented by BSD engineers somewhat later and aliases come from OS Classic.

Posted by grotsasha at April 30, 2007 1:29 PM