SEARCH

How-To Geek

Complete Guide to Symbolic Links (symlinks) on Windows or Linux

Want to easily access folders and files from different folders without maintaining duplicate copies?  Here’s how you can use Symbolic Links to link anything in Windows 7, Vista, XP, and Ubuntu.

image

So What Are Symbolic Links Anyway?

Symbolic links, otherwise known as symlinks, are basically advanced shortcuts. You can create symbolic links to individual files or folders, and then these will appear like they are stored in the folder with the symbolic link even though the symbolic link only points to their real location.

There are two types of symbolic links: hard and soft. Soft symbolic links work essentially the same as a standard shortcut.  When you open a soft link, you will be redirected to the folder where the files are stored.  However, a hard link makes it appear as though the file or folder actually exists at the location of the symbolic link, and your applications won’t know any different. Thus, hard links are of the most interest in this article.

Why should I use Symbolic Links?

There are many things we use symbolic links for, so here’s some of the top uses we can think of:

  • Sync any folder with Dropbox – say, sync your Pidgin Profile Across Computers
  • Move the settings folder for any program from its original location
  • Store your Music/Pictures/Videos on a second hard drive, but make them show up in your standard Music/Pictures/Videos folders so they’ll be detected my your media programs (Windows 7 Libraries can also be good for this)
  • Keep important files accessible from multiple locations
  • And more!

If you want to move files to a different drive or folder and then symbolically link them, follow these steps:

  • Close any programs that may be accessing that file or folder
  • Move the file or folder to the new desired location
  • Follow the correct instructions below for your operating system to create the symbolic link.

Caution: Make sure to never create a symbolic link inside of a symbolic link. For instance, don’t create a symbolic link to a file that’s contained in a symbolic linked folder. This can create a loop, which can cause millions of problems you don’t want to deal with. Seriously.

Create Symlinks in Any Edition of Windows in Explorer

Creating symlinks is usually difficult, but thanks to the free Link Shell Extension, you can create symbolic links in all modern version of Windows pain-free.  You need to download both Visual Studio 2005 redistributable, which contains the necessary prerequisites, and Link Shell Extension itself (links below).  Download the correct version (32 bit or 64 bit) for your computer.

Run and install the Visual Studio 2005 Redistributable installer first.

image

Then install the Link Shell Extension on your computer. Your taskbar will temporally disappear during the install, but will quickly come back.

image

Now you’re ready to start creating symbolic links.  Browse to the folder or file you want to create a symbolic link from.  Right-click the folder or file and select Pick Link Source.

image

To create your symlink, right-click in the folder you wish to save the symbolic link, select “Drop as…”, and then choose the type of link you want.  You can choose from several different options here; we chose the Hardlink Clone.  This will create a hard link to the file or folder we selected.  The Symbolic link option creates a soft link, while the smart copy will fully copy a folder containing symbolic links without breaking them.  These options can be useful as well.

image

Here’s our hard-linked folder on our desktop.  Notice that the folder looks like its contents are stored in Desktop\Downloads, when they are actually stored in C:\Users\Matthew\Desktop\Downloads.  Also, when links are created with the Link Shell Extension, they have a red arrow on them so you can still differentiate them.

image

And, this works the same way in XP as well.

image

Symlinks via Command Prompt

Or, for geeks who prefer working via command line, here’s how you can create symlinks in Command Prompt in Windows 7/Vista and XP.

In Windows 7/Vista

In Windows Vista and 7, we’ll use the mklink command to create symbolic links.  To use it, we have to open an administrator Command Prompt.  Enter “command” in your start menu search, right-click on Command Prompt, and select “Run as administrator”.

image

To create a symbolic link, we need to enter the following in command prompt:

mklink /prefix link_path file/folder_path

First, choose the correct prefix.  Mklink can create several types of links, including the following:

  • /D – creates a soft symbolic link, which is similar to a standard folder or file shortcut in Windows.  This is the default option, and mklink will use it if you do not enter a prefix.
  • /H – creates a hard link to a file
  • /J – creates a hard link to a directory or folder

So, once you’ve chosen the correct prefix, you need to enter the path you want for the symbolic link, and the path to the original file or folder.  For example, if I wanted a folder in my Dropbox folder to appear like it was also stored in my desktop, I would enter the following:

mklink /J C:\Users\Matthew\Desktop\Dropbox C:\Users\Matthew\Documents\Dropbox

Note that the first path was to the symbolic folder I wanted to create, while the second path was to the real folder.

Here, in this command prompt screenshot, you can see that I created a symbolic link of my Music folder to my desktop.

image

And here’s how it looks in Explorer.  Note that all of my music is “really” stored in C:\Users\Matthew\Music, but here it looks like it is stored in C:\Users\Matthew\Desktop\Music.

image

If your path has any spaces in it, you need to place quotes around it.  Note also that the link can have a different name than the file it links to.  For example, here I’m going to create a symbolic link to a document on my desktop:

mklink /H “C:\Users\Matthew\Desktop\ebook.pdf”  “C:\Users\Matthew\Downloads\Before You Call Tech Support.pdf”

Don’t forget the syntax:

mklink /prefix link_path Target_file/folder_path

In Windows XP

Windows XP doesn’t include built-in command prompt support for symbolic links, but we can use the free Junction tool instead.  Download Junction (link below), and unzip the folder.  Now open Command Prompt (click Start, select All Programs, then Accessories, and select Command Prompt), and enter cd followed by the path of the folder where you saved Junction.

image

Junction only creates hard symbolic links, since you can use shortcuts for soft ones.  To create a hard symlink, we need to enter the following in command prompt:

junction –s link_path file/folder_path

As with mklink in Windows 7 or Vista, if your file/folder path has spaces in it make sure to put quotes around your paths.  Also, as usual, your symlink can have a different name that the file/folder it points to.

Here, we’re going to create a symbolic link to our My Music folder on the desktop.  We entered:

junction -s “C:\Documents and Settings\Administrator\Desktop\Music” “C:\Documents and Settings\Administrator\My Documents\My Music”

image

And here’s the contents of our symlink.  Note that the path looks like these files are stored in a Music folder directly on the Desktop, when they are actually stored in My Documents\My Music.  Once again, this works with both folders and individual files.

image

Please Note: Junction would work the same in Windows 7 or Vista, but since they include a built-in symbolic link tool we found it better to use it on those versions of Windows.

Symlinks in Ubuntu

Unix-based operating systems have supported symbolic links since their inception, so it is straightforward to create symbolic links in Linux distros such as Ubuntu.  There’s no graphical way to create them like the Link Shell Extension for Windows, so we’ll just do it in Terminal.

Open terminal (open the Applications menu, select Accessories, and then click Terminal), and enter the following:

ln –s file/folder_path link_path

Note that this is opposite of the Windows commands; you put the source for the link first, and then the path second.

For example, let’s create a symbolic link of our Pictures folder in our Desktop.  To do this, we entered:

ln -s /home/maguay/Pictures /home/maguay/Desktop

image

Once again, here is the contents of our symlink folder.  The pictures look as if they’re stored directly in a Pictures folder on the Desktop, but they are actually stored in maguay\Pictures.

image

Delete Symlinks

Removing symbolic links is very simple – just delete the link!  Most of the command line utilities offer a way to delete a symbolic link via command prompt, but you don’t need to go to the trouble.

image

Conclusion

Symbolic links can be very handy, and we use them constantly to help us stay organized and keep our hard drives from overflowing.  Let us know how you use symbolic links on your computers!

Download Link Shell Extension for Windows 7, Vista, and XP

Download Junction for XP

Matthew digs up tasty bytes about Windows, Virtualization, and the cloud, and serves them up for all to enjoy!

  • Published 05/4/10

Comments (26)

  1. Thomas

    Hi,

    Quick question, couldn’t we use this technique to workaround the problem in Windows when saving data outside the “My Documents” folder and trying to redirect “My Documents” to the other drive?

    With my setup for example, I have a SSD for the OS and a 1To RAID1 for my data. Of course all my personnal data, music, pictures and so on are on D:\ (the RAID1). The problem I have is that (a) I do not want to mess around to try redirecting the User folders (I’m with W7) to the other disk as I’m afraid this will mes things up for little benefit; and (b) using librairies is not really an option because then the system backup I’m taking with the built-in backup tool will grow to hundreds of gigabytes as it will includes users’ folders.

    Wouldn’t it then be possible to bypass this with symlinks? If I store all my data on D:\ and in the User folders I create symlinks pointing to D:\, will it really physically include all data in my backup. Nevertheless, even if it does, i’ll have managed to point User folders (aka “My Documents”) to another drive. Right?

    Hope I was clear, I’ve typed tis in a hurry

    Thomas

  2. davide

    Thank for the HowTo, very good.

    A little question, is there a way to have tabs in Explorer ?? Like Firefox or IE8.

    bye

  3. Matthew Guay

    @Thomas – You could do it with symbolic links, but a better way would be to move the folder via the folder properties. Check out this article (which was written for Vista but works the same in 7) on how to move your documents folder the easy way :)
    http://www.howtogeek.com/howto/windows-vista/moving-your-personal-data-folders-in-windows-vista-the-easy-way/

  4. André-Yves

    “There’s no graphical way to create them like the Link Shell Extension for Windows, so we’ll just do it in Terminal.”

    In nautilus : right click on a folder >> make link.

  5. puimino

    “There’s no graphical way to create them like the Link Shell Extension for Windows, so we’ll just do it in Terminal.
    In nautilus : right click on a folder >> make link.”

    This is another way to do that:

    select the file/folder with the medium button and drag in, gnome then ask you what do you want: Move here, Copy here or Link here.

    another is select the file/folder and drag to the place, but before you release the button mouse, press the ctrl and shift keys. this works with XP too.

  6. Caio

    André-Yves is right, there is a graphical way of building links in linux, which I have used for a while now since I discovered it.

    As fas as I knew there are symbolic links and hard links. So hard links would be different from symbolic links, not a cathegory.

    The manual page of “ln” in linux says:
    ln -s, –symbolic
    make symbolic links instead of hard links

    And from my experience with symlinks (using ln -s) in linux, the os and apps think the directory acutually exists there, as both paths exist and are virtually independent (apart from the fact that they are actually the same location, but thats what links are all about), and not a simple shortcut as stated in the article.

    So anyone can clarify this for me?

  7. Caio

    wikpedia says:

    In computing, a symbolic link (also symlink or soft link) is a special type of file that contains a reference to another file or directory in the form of an absolute or relative path and that affects pathname resolution.

    So symlinks are actually completelly different from hard links(?)

    And at least in linux they do not simply work as shortcuts, that’s for sure, as even programs like wine use them to make emulated programs think they are reaching C:\Documents and Settings\User\My Documents when they are actually recinh /home/user/Documents: C:\Documents and Settings\User\My Documents is actually a symlink to /home/user/Documents.

    In my home folder Documents, Images, Videos etc. are all symlinks to the folders in my ntfs Windows partition. And they all work exactly as if they were actual directories in my linux ext4 partition.

  8. Caio

    edit: again in wikipedia:

    “Symbolic links are different from hard links. Hard links may not normally point to directories and they cannot link paths on different volumes. Symbolic links may point to any file or directory irrespective of the volumes on which the source and destination reside.”

  9. Caio

    Sorry for posting repetedly… but now that i read the whole article in wikipedia I’m convindec that the statement

    “There are two types of symbolic links: hard and soft. Soft symbolic links work essentially the same as a standard shortcut. When you open a soft link, you will be redirected to the folder where the files are stored. However, a hard link makes it appear as though the file or folder actually exists at the location of the symbolic link, and your applications won’t know any different. Thus, hard links are of the most interest in this article.”

    Is wrong. There is no such cathegories of symlinks as hard links are a different thing. All symlinks are soft links (which seems to be a different name for it anyway).

    And also as sated below:

    “Shortcuts, which are supported by the graphical file browsers of some operating systems, may resemble symbolic links but differ in a number of important ways. One difference is what type of software is able to follow them:

    * Symbolic links are automatically resolved by the file system. Any software program, upon accessing a symbolic link, will see the target instead, whether the program is aware of symbolic links or not.
    * Shortcuts are treated like ordinary files by the file system and by software programs that are not aware of them. Only software programs that understand shortcuts (such as the Windows shell and file browsers) treat them as references to other files.

    So in the matters discussed in the article there seems to be no need for a hard link. Which as explained in http://en.wikipedia.org/wiki/Hard_link is “harder” in the way that it is a reference to physical data in a hard drive instead of a reference to its path. But if symlinks are transparent to the user, the apps and the os there should be no need for hard links for the uses exemplified in this article.

    Please correct me if I’m wrong as I’m miles away from being an expert in these subjects and even more in this specific one.

  10. Robin

    You cite Visual Studio 2005 redistributable as a requirement and the Link Shell Extension link is to “Microsoft Visual C++ 2005 SP1 Redistributable Package (x86)”.

    I have Visual Studio 2005 installed (I think for MOSS 2007 Enterprise) and the about screen reports Visual C++ as an installed product.

    Does that meet the system requirement?

  11. Caio

    yeah.. i guess no one really cares

  12. Mike

    I am having trouble with this process to set up these links. I am on windows 7 64bit system. When I installed the Visual 2005 I lost all my customization on the Windows 7 Taskbar. I had to install Quicklaunch again. Now the taskbar operates differently than if did before. I used to be able to stack three levels of toolbars but I can only do two now. There is also too much assumed when creating these links. I expected some indication of something happening when I right clicked to pick the source. Then when I dropped as into the folder nothing happened until I refreshed the folder and there was the symlink. Anyway, I wish it were a little clearer instructions as to what is actually happening. Thanks though for providing this.

  13. Bert

    This article states that `mklink /J` creates a hard link to a directory. That is not true; it creates a so-called ‘directory junction’, which is more like a symbolic link than a hard link. In fact it behaves exactly like a symbolic link, only the windows internal machinery that handles the link is different.

  14. Ryan

    Just a quick note (something I found after reading your article). Windows XP actually does contain built-in command prompt support for symbolic links:

    http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/fsutil.mspx?mfr=true

    And unlike junction, it works for files too.

  15. Rune Sommer

    Removing Symlinks in Vista / 7 is harmless. But removing Synmlinks (or Junctions) in WinXP / 2000 will remove all the files in the junction-location (and the original location – which is “the same”). Deleting it to the trashcan will leave the junction-files (at the original location) intact – BUT – when deleting the trashcan, the files will be removed as well.
    http://en.wikipedia.org/wiki/NTFS_junction_point
    and
    http://forums.mozillazine.org/viewtopic.php?t=34490
    (the wery last post)

  16. Michael

    I’m running XP, and I’ve got a folder with hundreds of files in it. One specific file is the program configuration ini. I need that single file to be user specific. I need to link the file to the user’s space using a relative reference.

    Tried: subst U: “%UserProfile%”, and then using fsutil hardlink to create a link from the program directory to the user’s space, but it’s a hardlink, which means it’s the same for all users.

    Tried: using junction to link the whole folder, which works great, except I have duplicates of the whole folder which is over a GB for each user. Also when I run an update, only the logged on user gets the update completely and for everyone it crashes.

    Any other ideas? The Guide above says that junctions work for files and folders, but that’s not what I’m seeing.

    See above: In Windows XP…junction -s “C:\Documents and Settings\Administrator\Desktop\Music” “C:\Documents and Settings\Administrator\My Documents\My Music”…Once again, this works with both folders and individual files.

  17. Michael

    Also I noted that the junction program allows one to check to see if a file is a reparse point, and it also allows the removal of that reparse point, assuming the file is one. So if we can identify and delete file reparse points, we can create them? BUT HOW???

  18. Keith

    Can someone explain whether this is a feature or bug? It appears that on windows server 2008, some commands are symlink aware and others are not. The type command shows the contents of the target of a symlink, but the more command does not. (The dir output below has been cleaned up to remove irrelevant clutter.)

    C:\TEMP\keith\permstest>dir
    Volume in drive C has no label.
    Volume Serial Number is 0CA5-3EC5

    Directory of C:\TEMP\keith\permstest

    12/02/2010 03:59 PM .
    12/02/2010 03:59 PM ..
    12/02/2010 03:58 PM d1
    12/02/2010 03:59 PM d2.txt [d1\d2\d2.txt]

    C:\TEMP\keith\permstest>type d2.txt
    contents of d2.txt
    C:\TEMP\keith\permstest>more d2.txt
    <<<<<<<

  19. Keith

    Formatting got messed up last time – maybe this will be better.

    C:\TEMP\keith\permstest>dir
    Volume in drive C has no label.
    Volume Serial Number is 0CA5-3EC5

    Directory of C:\TEMP\keith\permstest

    12/02/2010 03:59 PM .
    12/02/2010 03:59 PM ..
    12/02/2010 03:58 PM d1
    12/02/2010 03:59 PM d2.txt [d1\d2\d2.txt]

    C:\TEMP\keith\permstest>type d2.txt
    contents of d2.txt
    C:\TEMP\keith\permstest>more d2.txt
    <<<<<<

  20. Keith

    Nope – anyway, d2.txt is a symlink to d1\d2\d2.txt. If you type it, you see the contents. If you more it, you get nothing. Redirecting the output of more to a file produces a 0 byte file.

  21. FaireDude

    Never Seems before !!! GOOOOOOOOOOOD! POST!

  22. Megagamerx1

    Very VERY useful for keeping files in sync in Dropbox on Ubuntu. I can just point the “Music” and “Documents” folders to folders in Dropbox and access them hassle free.

  23. ForestRJ

    Yes I am a N00b, but here it goes… I want to a sym-link for say 10 folders that will go to everyones /home/name folder. Each person has a single private folder they can store privates files and they have sole permissions, but the 10 I want to share are like (example) picture, background, setup, education, etc. I am trying to do it all command line.

    Is there a single ln -s etc command that will do this? or is this a line by line entry deal?

    Forest
    ubuntu 11.04

  24. C

    Great write-up, thanks!

  25. XP User

    Doesn’t work in XP. Only Vista and beyond

  26. Octoplayer

    Can you help explain this behavour with Word, or better still suggest a workaround?

    I want to collate several files in one directory under W7, and have edits replicated in other folders.
    I select my master word doc, (using LSE), Pick Link Source
    I drop a copy in another folder.
    Edit the master and save it. THe slave folder now appears empty, although there is a hidden copy of original file in it. Notepad behaves “correctly”, but I cannot create my masterpieces in that.

    How can I stop Word from creating a unlinked file when saving, and breaking the hard link?
    Is there an alternative to a hard link, ideally giving two-way replication of changes to a document? (I dont want to use a juncton to a folder, as that would mean I cannot list the sequential file names correctly).
    THanks

Enter Your Email Here to Get Access for Free:

Go check your email!