AliasesSymbolic linksHard links
All three types of links are shortcuts to an original file system object. A file system object is usually a file on your Mac, but it can also be a folder, a drive, or a networked device.
Overview of Aliases, Symbolic Links, and Hard Links
Shortcut links are small files that reference another file object. When the system encounters a shortcut link, it reads the file, which contains information about where the original object is located, and then proceeds to open that object. For the most part, this happens without the user recognizing they’ve encountered a link of some type. All three types of links appear transparent to the user or app that makes use of them. This transparency allows shortcut links to be used for many different purposes. One of the most common is to conveniently access a file or folder that is buried deep in the file system. For example, you may have created an accounting folder in your Documents folder for storing bank statements and other financial information. If you use this folder often, you can create an alias to it and position it on the desktop. Instead of using the Finder to navigate through multiple folder levels to access the accounting folder, you can click on its desktop alias. The alias takes you right to the folder and its files, short-circuiting a long navigation process. Another common use for file system shortcuts is to use the same data in multiple locations, without having to either duplicate the data or keep the data synced. Returning to the accounting folder example, you may have an application that you use to track stock market picks, and the app needs to store its data files in a predefined folder. Instead of copying the accounting folder to a second location and worrying about keeping the two folders in sync, you can create an alias or a symbolic link. That way, the stock trading app sees the data in its dedicated folder but accesses the data that’s stored in your accounting folder.
Aliases
The alias is the oldest and most popular shortcut for the Mac. Its roots go back to System 7. Most Mac users know how to create aliases and how to use them. Aliases are created and managed at the Finder level, which means that if you’re using Terminal or a non-Mac application, such as many UNIX apps and utilities, an alias won’t work for you. OS X and macOS see aliases as small data files, which they are, but they don’t know how to interpret the information they contain. This may seem to be a drawback, but aliases are the most powerful of the three types of shortcuts. For Mac users and apps, aliases are also the most versatile of the shortcuts. When you create an alias for an object, the system creates a small data file that includes the current path to the object, as well as the object’s inode name. Each object’s inode name is a long string of numbers, independent of the name you give the object and guaranteed to be unique to any volume or drive your Mac uses. After you create an alias file, you can move it to any location in your Mac’s file system as many times as you like, and it still points back to the original object. That’s clever, but aliases take the concept a step further. In addition to moving the alias, you can also move the original item anywhere in your Mac’s file system. The alias is still able to find the file. Aliases can perform this seemingly magic trick because they contain the inode name of the original item. Because each item’s inode name is unique, the system can always find the original file, no matter where you put it. The process works like this: When you access an alias, the system checks to see if the original item is at the pathname stored in the alias file. If it is, the system accesses it, and that’s that. If the object has moved, the system searches for a file that has the same inode name as the one stored in the alias file. When it finds a matching inode name, the system connects to the object.
Symbolic Links
Symbolic links (or symlinks) and hard links are less common, and they require a level of comfort in the Terminal application. A symbolic link is a type of shortcut that is part of UNIX and Linux file systems. Because OS X and macOS are built on top of UNIX, they fully support symbolic links. Symbolic links are similar to aliases in that they are small files that contain the pathname to the original object. However, unlike aliases, symbolic links don’t contain the inode name of the object. If you move the object to a different location, the symbolic link is broken, and the system can’t find the object. That may seem like a weakness, but it’s also a strength. Since symbolic links find an object by its pathname, if you replace an object with another object that bears the same name and is in the same location, the symbolic link continues to work. This makes symbolic links a natural for version control. For example, you could create a simple version control system for a text file called MyTextFile. You could save older versions of the file with a number or date appended, such as MyTextFile2, and save the current version of the file as MyTextFile.
Hard Links
Like symbolic links, hard links are part of the underlying UNIX file system. Hard links are small files that, like aliases, contain the original item’s inode name. Unlike aliases and symbolic links, hard links don’t contain the pathname to the original object. You typically use a hard link when you want a single file object to appear in multiple places. Unlike with aliases and symbolic links, you can’t delete the original hard-linked object from the file system without first removing all hard links to it.