Symbol link mac os

Use these shortcuts for quick access to files and folders

The Mac’s OS X and macOS operating systems support several types of shortcut links to files and folders. Shortcut links make it easy to navigate to objects that are buried deep within the file system. Macs support three types of shortcut links:

  • Aliases
  • Symbolic links
  • Hard 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.

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.

All three types of shortcuts are methods of accessing an object in your Mac’s file system from other than its original location. Each type of shortcut has unique features that are better suited for some uses than others.

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.

Читайте также:  Код ошибки 0х0000098 windows

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.

Making a file alias is simple. Select the file name in a Finder window, tap the cog icon, and select Make Alias.

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.

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.

Источник

Works differently than a regular shortcut

A symbolic link, often shortened to symlink, is a type of link that is stored at one location on your machine and it points to another location on the same machine. You can think of it as a shortcut of an app. Even though the actual app file is located deep inside your folders, you can simply double-click on the app shortcut on your desktop to launch the app.

A symlink is a type of shortcut, but it works differently than regular shortcuts. It’s less of a shortcut and more of the actual file it’s pointing to. Any app that you provide with your symlinks will think of these links as the actual files rather than normal shortcut files.

These are extremely useful as you don’t have to be stuck to a particular folder for an app to work. You can have your data stored in other folders and you can create a symlink in the original folder pointing to the new folder you’ve created. Your system and your apps will think you haven’t really made any changes and they’ll work normally, although things are otherwise.

Читайте также:  Органайзер папок для windows 10

Making a symlink on a Mac is extremely easy. The built-in Terminal app has a command that lets you easily create as many symlinks as you want on your Mac.

All that you need to know is the location where you want to create the symlink and the path where the symlink should point to. Once you have this information, here’s how you create a symlink in Terminal.

Launch the Terminal app using your preferred way on your Mac.

Type in the following command into the Terminal window and hit Enter. Make sure to replace destination with the folder you want the link to point to and location with the path where you want to save the link.

ln -s destination location

To create a symlink on your desktop that points to your Documents folder, you’d use the following command:

ln -s /Users/Mahesh/Documents /Users/Mahesh/Desktop

A symlink will be created and saved on your desktop. Double-click on it and it’ll open the Documents folder (if that’s what you specified above) in the Finder.

If the directory you want to create a symlink for has spaces in its names, make sure to enclose the path names with double quotes so as to avoid any errors.

You can now use this symlink in any of your commands and apps and it’ll be considered as the actual version of your folder or file.

Terminal isn’t the only way to create symlinks on your Mac. If you don’t happen to be a Terminal guy, you have an app available to let you create symlinks on your machine.

What this app does is it adds an option to your context menu so you can create symlinks by just right-clicking on your files and folders.

Head over to the SymbolicLinker page on GitHub and download and open the package on your Mac.

Copy the SymbolicLinker.service.app file from the package, hold down the Option key, click on the Go menu in the Finder, select Library, open the Services folder, and paste the file you copied.

Double-click on the app to open it. It won’t show anything but it has secretly added an option to your context menu.

Find the file or folder you want to create a symlink for, right-click on it, and select Services followed by Make Symbolic Link.

It’ll create the symlink in the same folder as the original file/folder. You can move it around though if you want.

The Automator method to create symlinks works pretty much the same way as the above method. But this one will suit those of you who don’t trust any random apps on the Internet, and you’d rather create something by yourself so you know exactly what it contains.

Launch the Automator app on your Mac.

Select Service followed by Choose to create a new Automator service on your Mac.

Set the options at the top as the following:

Service receives selected – files or folders

in – any application

In the actions list, search for the action named Run Shell Script and drag it over to the right panel.

Configure the action and the commands as the following:

Shell – /bin/bash

Pass input – as arguments

while [ $# -ne 0 ]; do
ln -s “$1” “$1 symlink”
shift
done

Save the service by clicking on the File menu at the top and selecting Save. Enter a meaningful name for the service and hit Save.

To create a symlink with the newly created Automator service, right-click on your file or folder and select Services followed by your service name.

You can also create a keyboard shortcut for the service to make creating symlinks even easier on your machine.

Symlinks don’t occupy much memory space as they’re just shortcuts to the files and folders on your machine. However, if you want to remove one or a few of these from your machine, you have two ways to do it.

Launch the Terminal app, type in the following command, and hit Enter. Make sure to replace symlink with the path of the symlink on your Mac.

Читайте также:  Ps4 controller with windows

rm symlink

Another way to delete a symlink is to use the context menu option. Right-click on your symlink and select Move to Trash. It’ll remove the symlink from your Mac.

Make sure to empty the Trash after you’re removed the symlink to ensure it’s gone for good from your Mac.

Conclusion

Symlinks are much more powerful than regular aliases as these work in all the apps and commands as if these were the real files.

Mahesh has been obsessed with technology since he got his first gadget a decade or so ago. Over the last few years, he’s written a number of tech articles on various online publications including but not limited to MakeTechEasier and Android AppStorm. Read Mahesh’s Full Bio

Источник

A symbolic link created at the command line allows a linked object in the file system to point to an original object in a different location. In this way, symbolic links behave much like an alias does in the Mac OS X GUI, except that the linking and reference between files or folders is done at a lower level, and thus can be pointed directly to by various applications or user purposes. This can be useful in many situations for advanced Mac users, from providing easier access to a particular location, to offloading an application folder to another hard drive, and much more.

To make and set a symbolic link at the command line in Mac OS X, you’ll want to use the ln command with the -s flag, without the -s flag a hard link is set, which is not what we’re looking to do here. Launch the Terminal to get started.

The basic syntax for creating a symbolic link (or soft link) is as follows:

ln -s /path/to/original/ /path/to/link

That will point /path/to/link to the original location, in this case /path/to/original/

For example, to create a symbolic link for the user Downloads folder which links it to a directory on a separate mounted drive, syntax may look like the following:

ln -s /Volumes/Storage/Downloads/

That will link the active users

/Downloads/ folder to a directory named “Downloads” on the mounted drive called “Storage”. If such a directory and drive existed, this would basically allow all files that would typically appear in the user downloads folder to go to the other mounted volume instead, essentially offloading the storage burden to that separate drive, while still preserving the appearance of a

/Downloads/ folder for the user. As mentioned before, this behaves much like an alias.

Another example would be to offer easier access to an otherwise buried binary by linking the command to /usr/sbin/

sudo ln -s /A/Deeply/Buried/Path/ToApp.framework/Resources/command /usr/sbin/commmand

This would allow the user to type ‘command’ and access the binary, without having to prefix the command execution with the entire path.

Soft links have tons of potential uses, and if you’ve been a longtime reader of OSXDaily you’ve undoubtedly come across them before in other articles, from gaining easier access to the powerful airport command, placing mounted NTFS volumes onto the desktop, to moving local iTunes iPhone backup folders to external drives, to adding a Trash can icon to the user desktop like retro Mac OS versions, or even placing an application cache folder onto a RAM disk for ultra-fast data access and caching. The practical uses are countless, and making symbolic links will work in any unix OS, so beyond Mac OS X you could apply the same idea to linux or FreeBSD.

Of course, created symbolic links sometime need to be undone. This is easy with rm, or by using the ‘unlink’ command as follows:

Essentially this is removing the tiny file (again, like an alias) that references the symbolic link to the original item.

Unlinking a symbolic link will not delete any files or folders other than that defined link, it simply removes the reference from the linked item to the original item.

Know of any particularly great uses or tricks with symbolic links? Let us know in the comments!

Источник

Оцените статью