How to Use Aliases, Symbolic Links, and Hard Links on Your Mac


Key Takeaways

  • Aliases in macOS are easy-to-create shortcuts that maintain a connection with the original file or folder even when relocated.
  • Symbolic links offer cross-filesystem linking but require updates if the original file or folder is moved.
  • Hard links are useful for version control and data backup and can be created easily within the same filesystem in macOS.

macOS supports three main types of linking for referencing files and folders within the file system on a Mac: hard links, symbolic links (symlinks), and aliases. Each works differently and serves a different purpose. So, how do you decide which one to use?

Aliases

An alias is a simple shortcut to a file or folder present in one location on your file system at another location. It’s a convenient way to improve the accessibility of your frequently-used files or folders buried deep in the file system on your Mac, though it only works within the Finder app.

When you create an alias, it stores both the pathname to the original file or folder and the inode number (unique identification of files and folders within the filesystem). This adds robustness, as the use of pathname simplifies access, while the inclusion of inode ensures an alias can maintain its connection to the original file or folder even when it’s relocated within the filesystem.

As such, you won’t have to update your aliases every time you move their associated original files or folders to another location. That said, an alias becomes invalid the moment you move the original file or folder to another disk. Similarly, it won’t function when you delete the original objects, either.

An alias on macOS has a small arrow on its icon. Opening an alias takes you directly to the original file or folder. You can also rename the alias or move it to your preferred location. If you no longer need the alias, you can delete it, and your original file or folder will remain intact.

How to Create an Alias on a Mac

You can create an alias on your Mac in multiple ways. However, the easiest way is to navigate to the folder containing the file or folder you want to create an alias for, Option-click it, and select “Make Alias” from the menu.

Make Alias option in the context menu for a file to create its alias.

This will create an alias in the same folder. Drag the alias out of the current folder to your preferred location for easier access.

Alternatively, you can create an alias in one go using a keyboard shortcut. Simply hold down the Command and Option keys while dragging the file or folder for which you want to create an alias to your desired location on your Mac.

A symbolic link (or symlink), also referred to as a soft link, is another way to create a file or folder shortcut on a Mac. You can think of it as an advanced shortcut that largely serves the same purpose as an alias but works across different filesystems and is accessible by various applications, including command-line tools and not just Finder.

Although a symbolic link relies on a file or folder’s pathname to establish a reference, similar to an alias, it doesn’t include the inode name. As a result, if you rename or move the original file or folder to another location, it breaks the symbolic link, making it unusable. Hence, you need to be sure to update your symbolic links when you change locations for the original file or folder to avoid ending up with dangling links.

That said, not including the inode name also gives symbolic links an advantage. Since the symbolic link points only to the pathname, it allows for cross-filesystem linking, meaning you can reference files across different filesystems. This makes it perfect for managing and organizing files and folders on different storage devices.

So you might use a symbolic link to store files on an external drive by making it appear to your Mac (and any applications you use) that the files are stored in place. In reality, the symbolic link acts as a signpost.

Symbolic links look similar to aliases with an arrow in the bottom-left corner of their icon.

There are two ways to create symbolic links on a Mac. If it’s a one-time affair, you can use the Terminal app on your Mac to quickly create a symbolic link. However, if you feel you may have to create symbolic links more often, you can set up a Quick Action in Automator that lets you do it more efficiently.

To do this, open Automator on your Mac and select “New Document.” Select “Quick Action” as your document type and hit “Choose.”

Click the drop-down for “Workflow Receives Current” and select “Files or Folders.” Make sure the “In” drop-down is set to “Any Application.”

Setting Workflow Receives Current and In options for a Quick Action in Automator app.

Now, look up the “Run Shell Script” action from the sidebar and drag it to the main window. Use the drop-down button next to “Shell” and choose your default shell. Click the drop-down for “Pass Input” and select “As Arguments.”

Configuring the Shell and Pass Input options for the Run Shell Script action in Automator.

Copy the following script and paste it into the empty window in Automator:

        for f in "$@"
do
  ln -s "$f" "$f symlink"
done

Finally, save the Quick Action. Go to “File” > “Save,” give it a name, and hit “Save.”

With your Quick Action ready, creating a symlink with it is easy. Simply Control-click (right-click) on the file or folder for which you want to create a symbolic link, hover over “Quick Actions,” and select the Quick Action you just created.

Using the General Symlink Quick Action on a file to create a symbolic link on a Mac.

You’ll now have a symbolic link for the file or folder inside the same folder.

A hard link isn’t technically a shortcut, unlike a symbolic link and alias, but it, too, is a way to reference files on a Mac. It solely uses the inode name to reference objects, which serves two purposes.

First, it allows the hard link to not take up much storage space, so you can create as many of them on your Mac as you want. This is great because you typically create hard links when you want to reference a single file at multiple locations on your Mac.

Second, it allows you to make changes to any of your hard links for a file and have them reflect on all the linked filenames. Because of this, you can use hard links for version control and data backup.

However, since hard links rely on inode for referencing, they need to reside within the same filesystem to remain accessible. In addition, unlike aliases and symbolic links, you can’t have hard links for folders on your Mac due to system restrictions.

Similar to aliases and symbolic links, hard links also have an icon with an arrow on top of it.

Creating a hard link on a Mac is easy. Open the Terminal app on your Mac and use the “cd” command to navigate to the folder containing the original file.

Then, type your command in the following syntax, replacing “orginal_file_name” and “hard_link_name” appropriately:

        ln original_file_name hard_link_name
    

Once created, you can move the hard link to anywhere on your Mac. You can also rename it if you want, and it won’t break it.


Knowing how different macOS link types work and how to create them will help you better organize and manage files on your Mac and streamline your workflow. But before you jump in to create a reference for a file or folder on your Mac, be sure to assess your requirements, as not all link types suit everyone’s needs, and picking the wrong one can run you into undesirable issues.



Source link

Previous articleApple’s iOS 18.2 update will arrive on Wednesday