Addendum: Symbolic Links
A lot of people not steeped in Unix culture do not know what symbolic links are, particularly Mac users who don't understand the differences between Mac OS aliases and Unix symbolic links, or "symlinks." But it's such a simple concept, it's worth taking a few seconds to explain it.
Symlinks are files that contain a string that is interpreted as a file path. Let's look at that sentence a piece at a time.
- "Symlinks are files..." That means they can be moved, renamed, and deleted just like any other file.
- "...that contain a string" Yes, they really do contain a plain old text string. Depending on the OS, the contents of symlink files may not be accessible. But rest assured, at the lowest level it's just a file containing text.
- "...that is interpreted as a path" This is the only vaguely tricky part for people who have never used a system that required them to understand paths. It is explained further below.
A path is a series words separated by an aptly-named "path separator" character. In Unix-style systems (like Mac OS X), the forward-slash (or just "slash") character "/" is the path separator. Each component of the path corresponds to a file or directory. Every path component but the last one must be a directory name. The last path component can be either a directory or file name. Thus, a path leads to a particular file or directory in the file system. Some examples of paths appear below:
Paths maybe either "absolute" or "relative." Absolute paths begin from the very top of the directory tree and therefore always correspond to the same file or directory no matter where the symlink file containing that path is moved.
Relative paths correspond to the file or directory located at a particular path starting from the current directory. The "current" directory for symlinks is the directory that contains the symlink file. This all sounds complex, but it's really not. Examples:
Let's say we have two symlink files:
- symlink1 contains a text string that spells out the following absolute path: /Food/Apple
- symlink2 contains a text string that spells out the following relative path (note the missing slash at the start): Food/Apple
Now let's look at the simple directory structure below:
/MyDisk/ Food/ Apple Special/ Food/ Apple
No matter where we put symlink1 on MyDisk, it will always point to the Apple file in the Food directory at the top level of MyDisk.
symlink2, on the other hand, could point to either the Apple file in the top level Food directory, or the Apple file in the Food directory inside the Special directory, or, perhaps, to nothing at all! Examples:
Example 1: symlink2 pointing to the "non-special" Apple file:
/MyDisk/ symlink2 -> Food/Apple Food/ Apple (symlink2 points to this) Special/ Food/ Apple
Example 2: symlink2 pointing to the Apple file in the Food directory inside the Special directory. Note that the Special directory could be moved anywhere on the filesystem and symlink2 would still point to the same file. This is the benefit of using relative links.
/MyDisk/ Food/ Apple Special/ symlink2 -> Food/Apple Food/ Apple (symlink2 points to this now)
Example 3: symlink2 pointing to nothing at all!
/MyDisk/ Food/ symlink2 -> Food/Apple Apple Special/ Food/ Apple
This last example is what's called a "broken" symlink. Any attempt to get at the file that symlink2 points to would fail with a "file not found" error. This can also happen if any of the files that either symlink1 or symlink2 point to are removed or renamed. Symlinks are "dumb" in this respect. They just contain a string, after all. If that string does not correspond to an existing file, the symlink is considered "broken."
Mac OS aliases are very different beasts. They 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. (How it does this is beyond the scope of this discussion.)
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, but sometimes you simply want to point to "whatever file happens to be located at the following path..." Exercise for the reader: why are relative symbolic links used in Framework Bundles instead of absolute symbolic links or aliases?