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

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.

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.

Additional Notes

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

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.

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.

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.

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).

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.

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!

Get the best tips from MakeUseOf in your inbox, free!

Peter E

August 27, 2013

I use Ubuntu One to sync my files, particularly the photo’s that I take on my mobile phone.

I also use shotwell phot omanager on my Ubuntu build. When you open Shotwell, you can program it to check your ‘Pictures’ folder and update any pictures there, however, you cannot manually select any folder you wish. Therefore I created a symbolic link in my pictures folder to my ubuntu one mobile pictures folder.

Now, when I take a photo on my phone, it is automatically synched with Ubuntu One, then when I get home and open Shotwell, it magically appears there too :)

Danny Stieben

Rick

August 27, 2013

I’m pretty sure this is the same thing. It works great on an Android phone for certain apps with large secondary files that insist on being in internal storage. Google Play Music is one in particular. If you pin music for offline use, it downloads them to internal storage and there is no option to move it elsewhere on newer phones (ironic that older ones do this by default, store pinned music to the sd card that is). But with a symbolic link, you can move the entire music folder to the sd card while the phone still thinks it is using internal. Very helpful if your phone only has a gig or two of internal storage space.

Danny Stieben

August 31, 2013

I assume that requires a rooted device so that you can create the symbolic link in the first place, correct?

Rick

August 31, 2013

I’m not 100% sure about that, but I assume so. I am rooted. If it is a system app, I would guess that you definitely need to be rooted to do this. If it’s a user app, possibly not? I don’t know. I did use Root Explorer to do it. I don’t see the same “Create Shortcut” option in ES File Explorer, but some other file manager apps may have the same ability.

Apparently, it doesn’t work in all cases though. I tried to move my upload folder for my Eye-Fi camera card into the camera folder on my phone, so the pics would upload automatically into Dropbox, but it wouldn’t let me create the shortcut back to the original location. If you aren’t familiar, this SD card uses its own wifi to upload pics from my camera to the Eye-Fi app on my phone, where I can look at them better than on the tiny little camera screen. Then, as soon as I get home and on my wifi there, the phone automatically uploads them to the Eye-Fi application on my computer. Pretty nice! But I’ve been wanting to play around more with Linux, dual booting it on my desktop. Eye-Fi is for Windows (and maybe Mac). So I was hoping to use the automatic upload to Dropbox as a workaround to get to my pics in Linux , rather than having to boot into Windows every time I take some pictures.

That leads me to another question. If I install Dropbox in Ubuntu, can I navigate it to use the Dropbox folder that already exists in the Windows file system? Will Linux and/or Dropbox let me do that? I know that you can tell Dropbox where to put its folder but I don’t know if that works across two platforms on the same machine. Would a symbolic link be a way to do this? I certainly don’t want two duplicate Dropbox folders on the same computer.

Rick

August 31, 2013

That actually seems to have worked. I have my Dropbox folder inside my Documents folder in Windows. So I navigated to the Windows “Documents” folder from within Ubuntu. Then I created a link to that folder and moved it to the “Home” folder in Ubuntu. Then, in the setup for Dropbox, I told it to put the “Dropbox” folder inside the link to “Documents”. It promptly told me there was already a folder named “Dropbox” there, and asked if I would like to merge the files. I told it yes, and everything is in the process of synching right now. Windows and Linux sharing the same Dropbox folder on the same computer. Now I just need to figure out the Eye-Fi problem.

Navigate back to the application’s folder, in this example: /home/danny/Application/data

Next you would create the symbolic link IN that folder, such as: ln -s /home/danny/documents/profile.bin /home/danny/Application/data/profile.bin

This follows the article’s description for creating the symbolic link in the manner of ln -s [source file] [destination].

Incidentally, when creating the link as above, you can choose any name for the link by choosing a different name in the destination path. EG: ln -s [/sourcepath/apples.doc] [/destinationpath/bananas.doc].

This example uses the ubuntu terminal commands. you would need to find out the commands for your particularly OS.

Peter E

August 28, 2013

incidentally, I mentioned you can change the file name of the symbolic link on creation of the link, but for your purpose, you must not, as the app you refer to wont be looking for your new filename, but the intended filename.

Do I need to create a file in the destination first? Or do I just type one big command line? If so, can you please show me the command line so I can type “as is”? Don’t suggest any options or niceties for now — just what’s needed to establish the symbolic link. Thanks!

Peter E

August 29, 2013

ok, so you need to use the make link command if you are using windows. To do this, you need to use the windows console.

First:

Navigate to C:Userdannyappdatacontacts manager, right click the ‘Contacts.db’ file and select cut. Next, navigate to C:userdannydocuments then right click and choose paste.

Then:

Click Start Menu and in the ‘Run’ box (or Search for files and folders box in windows 7) type cmd.exe.

using your example of the file’s location enter the following command:

Mac W

neo269

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

August 31, 2013

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.

Greg Webb

August 29, 2013

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

August 31, 2013

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

August 31, 2013

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.

Lazza

August 29, 2013

«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.

Danny Stieben

August 31, 2013

I’m sorry if those happen to be wrong — I’m sure I got the concept down, but the naming conventions are pretty difficult to differentiate. Haha.