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.

symbolic links dropbox   What Is a Symbolic Link & What Are Its Uses? [MakeUseOf Explains]
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.

symbolic links file list   What Is a Symbolic Link & What Are Its Uses? [MakeUseOf Explains]

  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   What Is a Symbolic Link & What Are Its Uses? [MakeUseOf Explains]
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

The comments were closed because the article is more than 180 days old.

If you have any questions related to what's mentioned in the article or need help with any computer issue, ask it on MakeUseOf Answers—We and our community will be more than happy to help.

22 Comments -

0 votes

Peter E

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

0 votes

Danny Stieben

Great example! Thanks for sharing, Peter!

0 votes

Rick

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.

0 votes

Danny Stieben

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

0 votes

Rick

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.

0 votes

Rick

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.

0 votes

ReadandShare

Danny (or anyone else who knows):

I have an app that writes data in its own folder — with no option to write to my Documents folder instead.

I like to have all my data in one folder (Documents) — to make it easier and foolproof when backing up to an external drive.

Would adding a symbolic shortcut in the Documents folder that points back to the app folder do the trick — and allow for backing up as described above?

0 votes

Peter E

That’s exactly how a symbolic link may be used. Without knowing what operating system you use, I couldn’t tell you specifically, but it essentially goes something like this:

The app writes data by default to /home/danny/Application/data in a file named profile.bin.

Move ‘profile.bin’ to your Documents folder (eg /home/danny/documents/profile.bin)

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.

0 votes

Peter E

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.

0 votes

ReadandShare

Ahhh… I am confused — sorry, but I am quite unfamiliar with command lines. Given:

1. source data file c:\user\dany\appdata\contacts manager\contacts.db
2. destination: c:\user\danny\documents

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!

0 votes

Peter E

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:

mklink /H C:Userdannydocumentscontacts.db C:Usersdannyappdatacontacts managercontacts.db

Use at your own risk. you need to ensure you have the correct path information etc.. Please ensure you back up your data first and create a restore point so that you can undo any mistakes you make.

For more information on symbolic links and a windows based GUI application for making symbolic links visit:

http://www.howtogeek.com/howto/16226/complete-guide-to-symbolic-links-symlinks-on-windows-or-linux/

(sorry to link a different tech website.. is this allowed MUO?)

0 votes

Peter E

sorry, for some reason the ‘s were removed from the path’s in the above explanation but im sure you can see what to do.

0 votes

Mac W

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

0 votes

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?

0 votes

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.

0 votes

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.

0 votes

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.

0 votes

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.

0 votes

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.

0 votes

Danny Stieben

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.

0 votes
0 votes

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