What Is a Symbolic Link & What Are Its Uses? [MakeUseOf Explains]

What Is a Symbolic Link & What Are Its Uses? [MakeUseOf Explains]

Ads by Google

Is it a ghost file? Is it a clone? It’s a symbolic link, and it’s so useful it just might blow your mind.

Every operating system has a helpful feature called symbolic links. This offers you a lot of benefits when combined with other applications or techniques. The ability to create symbolic links is a feature unknown to most computer users, but understanding the concept isn’t very difficult. I’ll explain what they’re all about and how you can use them to get out of your computer and installed services.

Wait, Aren’t They Just Shortcuts?

A good place to start is to imagine that symbolic links are like shortcut files — but don’t think that they’re the same. A shortcut file is a file that simply points to the desired file. Windows users are familiar with these shortcut files, as any installer will place a shortcut on your desktop to make it easier to run a program. A symbolic link, on the other hand, is a lower-level pointer that is written into the file system on your hard drive.

A symbolic link will make it look like the linked file is actually there, rather than it just being a shortcut. However, once you click on it, it’ll still be directed toward the actual file location and run the data found there. As reference for the curious, technically speaking a symbolic link is for a directory, a hard link is for a file, and a soft link is another term for a shortcut.

Case Study

To better understand this, we’ll go into our first case study: use of symbolic links with Dropbox. If you’re wanting to synchronize something that you’d really rather have in a different folder besides the “Dropbox” folder, or if it’s something that can’t be moved without breaking some sort of functionality, you’ll have to find an alternate way to get Dropbox to synchronize those files.

For example, let’s say that you want to synchronize an entire folder (named “MakeUseOf”) that is full of files. If you create a shortcut in your Dropbox folder that points to the MakeUseOf folder, Dropbox will see the shortcut file and synchronize it. On another computer, you’ll see the same shortcut file, but if you click on it, you’ll come to a dead end. In this case, Dropbox just synchronized the shortcut file rather than the folder that the shortcut was pointing to.

symbolic_links_dropbox
To fix this issue, you can create a symbolic link. Since the symbolic link makes it look like the MakeUseOf folder exists in the Dropbox folder, even though it’s actually somewhere else, Dropbox will follow the symbolic link and start synchronizing the folder along with its contents. On the other computer, you’ll now have the MakeUseOf folder and its contents rather than just an invalid shortcut file.

Ads by Google

Additional Notes

There are four additional notes about symbolic links that you should be aware of.

symbolic_links_file_list

  1. Although most applications will see symbolic links as the actual files they point to, they can still be distinguished as symbolic links via terminal tools. For example, Linux users can use the “ls -la” command and discover all of the symbolic links in the current folder.
  2. A joy about symbolic links is that they maintain the folder structure in which the symbolic link is contained. So, for example, let’s say a file named HelloWorld.txt was in the MakeUseOf folder and located at /home/danny/MakeUseOf/HelloWorld.txt. If a symbolic link for the MakeUseOf folder was created in the Dropbox folder, and you went to look for HelloWorld.txt within the Dropbox folder, the file path would read /home/danny/Dropbox/MakeUseOf/HelloWorld.txt rather than transforming back to the original/actual file path. This is a major reason why symbolic links work so well to “fool” applications such as Dropbox without causing them to crash in confusion.
  3. Symbolic links update themselves when the contents of the source file have changed, but they won’t update the symbolic path they form if the source file has been moved or deleted.
  4. The system won’t prevent you from creating a symbolic link within a symbolic link, so try to avoid doing so yourself. This will otherwise create an infinite loop that can cause issues for system-wide services like antivirus scanners.

Applicable Uses

Of course, as we’ve already discussed extensively, a primary reason for desktop users to use symbolic links is to extend the functionality of applications such as Dropbox and other similar cloud services like ownCloud and Copy. Additionally, it can also be used to create different locations for primary user folder such as “Music”, “Documents”, and ‘Pictures” (i.e. move those folders from your C:\ drive or Home folder to another location such as a secondary, larger hard drive).

Those are just a few ideas, but the full extent of the usefulness of symbolic links is limited only to your imagination.Mac OS X users can even synchronize their Mac apps via Dropbox.

Creating Symbolic Links

Now that you’ve been thoroughly schooled on the concept of symbolic links, how do you create them? This varies slightly among operating systems, but all of them require that you use a terminal/command line to create one. Under Windows, you can use the command mklink [flag] [source] [destination] to create a symbolic link to a directory. You must use the /j flag if you’re dealing with directories, the /h flag if you’re dealing with a file, or /d to essentially create a soft link/shortcut. For [source] and [destination], you’ll need to provide the paths to the files or folders in question.

symbolic_links_creation
Under Mac OS X and Linux, you can create a symbolic link by using the command “ln -s [source] [destination]”. This works for both files and folders so this one command is all you need. However, if you’re a Mac user who don’t want to dabble in the terminal, you can also use Automator to create a symbolic link.

Conclusion

Despite their usefulness, symbolic links are still more confusing to use than simple shortcuts — which is why they can’t be easily created in a graphical user interface. A lot of computer illiterate people don’t even understand the concept of shortcuts very well (i.e. they think a program has been uninstalled whenever they simply delete the shortcut off of their desktop), so including an easy way to create symbolic links could potentially cause problems. However, you shouldn’t have these issues after reading this article, so have fun!

Have you used symbolic links before? If so, what has been your most creative use? Let us know in the comments!

Image Credit: Almond Butterscotch

Join live MakeUseOf Groups on Grouvi App Join live Groups on Grouvi
Best Linux Apps
Best Linux Apps
6 Members
Linux for New Switchers
Linux for New Switchers
9 Members
Linux Distros Talk
Linux Distros Talk
4 Members
Master the Linux Command Line
Master the Linux Command Line
6 Members
Ads by Google
Comments (22)
  • moorpipe

    I’m sorry to say but your description of MKLINK is confusing. Perhaps you’re not quite familiar with the existing linking mechanisms. Please refer to an explanation of MKLINK here: http://technet.microsoft.com/en-us/library/cc753194(v=ws.10).aspx
    For a very good article on junctions, symbolic and hard links, please check out:
    http://comptb.cects.com/2268-overview-to-understanding-hard-links-junction-points-and-symbolic-links-in-windows

  • Lazza

    «technically speaking a symbolic link is for a directory, a hard link is for a file, and a soft link is another term for a shortcut»
    This is completely wrong. In any operating systems class they teach you that symbolic links are different from hard links, and you can create them both for files and folders.

    Also, you can create a symbolic link from Ubuntu graphically, by selecting something and choosing “link to desktop” (sorry, I don’t know the exact wording in English) then you can move the new symlink in any folder you want, renaming it as you wish. I guess it’s the same also for other distributions and DEs.

  • Greg Webb

    I think symbolic links are great BUT there is one downside to spoil the joy. Backup programs may not understand symbolic links, and further more users may not know what to do with them when they use a backup program that does.

    The issue is, should a backup program backup the files from the symbolic link? You may end up with TWO copies of the files at the end of the symbolic link.

    The issue is so complex that I only use symbolic links on very rare occasions. I once had lots, having discovered the advantages, but got badly burned with backups.

    • Danny Stieben

      I’m not quite sure I understand this. Unless you actually have two copies or you create a loop via symbolic links, it shouldn’t back up two copies of the same file.

    • Greg Webb

      Hi Danny, Say you have two drives: C and D. On D you want to have a shortcut to C:\Program Files from D which you create with a symbolic link (I don’t why you’d want to do this but it’s useful for this explanation). Let’s say the the path of the symbolic link is D:\My Programs\WinProgs. When you do a backup of the D drive, should the backup copy the symbolic link itself or the files represented by the symbolic link (ie the contents of C:\Program Files).

      I would argue that in some circumstances you want only the link and other times you’d want the contents of the linked to directory. It then comes down to:
      (1) what do you want,
      (2) will your backup program recognise the symbolic link and ask you what you want to do.

      Two copies: If you back up both C and D, you may end up with two copies of \Program Files.

  • neo269

    I have created a symbolic link in Drop box. as follows

    Folder A is dropbox
    Folder B is folder which I want to sync with drop box
    So I create a symbolic link in Dropbox. i.e. \\A\B

    Now how do I update the Symbolic link folder B when actual folder B is updated?

    • Danny Stieben

      It should update automatically. The only issue that may appear is if you move folder B to a new location, because the symbolic link will still point to the old location. In this case, you’d simply have to delete the symbolic link and recreate it.

  • Mac W

    Mostly use symbolic link to have DropBox to sync folders outside the Dropbox-folder

Load 10 more
Affiliate Disclamer

This review may contain affiliate links, which pays us a small compensation if you do decide to make a purchase based on our recommendation. Our judgement is in no way biased, and our recommendations are always based on the merits of the items.

For more details, please read our disclosure.
Affiliate Disclamer

This review may contain affiliate links, which pays us a small compensation if you do decide to make a purchase based on our recommendation. Our judgement is in no way biased, and our recommendations are always based on the merits of the items.

For more details, please read our disclosure.