TIPS, BLOGS & TUTORIALS
I’ve seen hard links discussed in reference to Final Cut Pro X recently. I wanted to find out more about what hard links are so I dove into the shallow end of the online UNIX swimming pool. On the surface they are not that complicated. In this article, I've tried to keep the explanations as simple, non-technical and as clear as possible.
Symlinks versus hard links.
A symbolic link (also known as symlink or soft link) is a special type of file containing a filesystem path to another file or directory. The symlink is a second file that exists independently of its target. If a symlink is deleted, its target remains unaffected. If a symlink's target is moved, renamed or deleted, the symlink is not automatically updated or deleted. It continues to exist and still points to the old target.
A symlink is not a direct link to a file.
When you make a file in Mac OS X, you give that file a name. This file's name, stored in the directory, is not a separate file like a symlink is. It is possible to create a number of different names that all refer to that same file. Those names are hard links. Technically a hard link is a directory entry that associates a name with a file on a file system. To put it another way, hard links are any name(s) assigned to a single file.
As an analogy, hard links are like different names by which one person might be called. Say Person X has Bob as his first name and Thomas, as his middle name.
Some people call Person X "Bob", (his workmates) and some call him "Thomas" (his family, to avoid confusion since his father was also named Bob). Both names, Bob and Thomas, refer to one person. If Bob steps on the scale it says 200 pounds. If Thomas steps on the scale it says 200 pounds. And since they are the same person, both Bob and Thomas weighs 200 pounds total.
Caution! Technical stuff you don't really need to know follows.
All hard links actually point to a single inode number (index node number). An inode number is a data structure used to represent a filesystem object. Each inode stores the attributes and disk block location(s) of the filesystem object's data. In other words, an inode keeps track of where the data of a given file lives on a hard drive and the attributes of that data.
There is no "real" name versus hard link names. The original name and all hard links are equal. If you had a name plus two hard links assigned to a single file, they would all link to the same unique inode number and file. In order to delete a file, all names and hardlinks to that file must be deleted. When you delete a file in the Finder, you are actually just deleting the file's name in the directory and not the file itself. That's why data can usually be recovered from a hard drive when you "delete" a file.
Since both the original name and any hard links actually point to one single file, each name will reflect the entire amount of data in that single file. But the total amount of data the file and associated hard links actually use on a disk will be the amount of data in the single file. The total is not the sum of every name or hard link's referenced data.
You can delete the original name given to a file on creation and if a hard link exists, the file still exists. If the file is opened by one of its names, and changes are made to its content, these changes will be reflected when the file is opened by an alternative name.
For those who use Terminal, you can make a hard link using the Terminal command ln original newname where "ln" is the hard link command, "original" is the existing file name and "newname" is the new name for the hard link.
Similarly, you make a symlink by using the Terminal command ln -s original symlink where "original" is the existing file name and "symlink" is the symlink. I make symlinks with PathFinder.
Usually you don't have to make hard links or symlinks though. Final Cut Pro X (and Time Machine for that matter) handles that automatically when it is needed during media management operations.