How-To: Use Symbolic Links to Master Vista's File System
Posted 05/13/09 at 10:45:00 AM by Alex Castle
With Windows Vista, Microsoft introduced a new capability into its operating system: the ability to create symbolic links. Accessible only from the command line, symbolic links aren’t something the average user would need to be familiar with to use Windows, but they are a powerful way to manipulate the file system. In this article, we’ll provide a little background info about symbolic links and hard links, and show you how to use the mklink command to create them. We’ll also show you a couple of examples, including how to use mklink to manage your Steam games and music files. so read on, and find out how you could be taking full advantage of symbolic links!
What is a symbolic link?
A symbolic link is very much like what you would normally call a “shortcut.” it creates a pointer to a different part of the file system, redirecting your computer to that location when accessed. What makes a symbolic link different from a shortcut is that it is handled at the operating system level, rather than at the application level. This means that whereas only a few programs (such as explorer.exe) know how to handle a shortcut file, a symbolic link can be used with almost any program that deals with the file system.
With a symbolic link, if the target directory or file is deleted, the link becomes non-functioning, as it points to a file that no longer exists. In a way, this gives symbolic links extra flexibility, as you can create a symbolic link to a file or folder that doesn’t actually exist, but will later. Symbolic links take up no space, and if you delete a symbolic link, nothing happens to the original data.

It's actually considerably more complicated than what's shown in the above graph, but this gives you an idea of the structure a symbolic link creates.
What is a hard link?
A hard link is functionally very similar to a symbolic link, but is fundamentally different. Rather than pointing to a part of the file system, a hardlink points to data in memory. In other words, when you create a hard link, you’re not merely creating a link or a shortcut to another file—you’re creating a new file which points to already extant data.
This is best illustrated by mentioning that if you delete the original file, any hard links to that file will still work normally, as the data they pointed to is still there. The data will remain until every hard link pointing to it is deleted.

How to use the mklink command
To create a symbolic link with mklink, use the following syntax:
mklink <link> <target>
The parameter <link> is the name you want to give to the newly created link. The <target> parameter is where you specify the location that you want to link to. The location can be an absolute path (such as “C:\Documents and Settings\acastle\My Documents\Articles”), a relative path (such as “Articles\October 08”), or the address of a network share (such as 192.168.1.3). The target can be a single file or an entire folder, depending on which command line options are specified. These options are as follows:
Default
If you use mklink without any command line flags, it will default to creating a file symbolic link. Thus, the specified target must be a single file. For example, to link a game save file to a mounted network drive, you could enter
mklink D:\Games \civilization iv\game1.sav M:\Games\civilization iv\game1.sav
/D
With the /D flag, mklink creates a directory symbolic link. This is just a symbolic link that points to a whole directory rather than a file. You would generally use such a link the same way you would use a shortcut to a directory. As an example, it could look like this:
mklink D:\Photos \\192.168.1.4\photos
/H
With the /H flag, mklink creates a hard link, rather than a soft link, as described at the beginning of this article. It must point to a file, not a directory. It would look like this:
mklink /H C:\app\config.ini E:\apps\exampleapp\config.ini
/J
The /J flag is the hard link equivalent of the /D flag. It creates a hard link to a directory, rather than a single file. For example, if you wanted to create a hard link to a folder, you could use this command:
mklink /J D:\Articles C:\Users\username\Documents\Articles
If at any time you simply enter "mklink" into the command prompt, you'll be shown a brief reminder of what the command line options are.
Sample Uses
Alright, so that was a whole lot of theory about symbolic links, but what are they actually good for? As a basic tool for manipulating the file system, they’ve got potentially endless uses, but most of the ways we’ve used the in the past involve using hard links to provide extra flexibility for applications that don’t normally allow you to change where certain data is stored. For example:
Storing Steam Games Outside the Steam Folder
Steam is an excellent example of a application which is not entirely flexible in the way it uses the file system. When you first install Steam, you can choose where you want games saved, but after that point, every new game you download is installed to the same place. With hard links, we can fix that.
Why would we want to have Steam games installed in different places? Let’s look at the following example. Say we have a computer with two hard drives: a 300GB WD Velociraptor and a 1.5TB Seagate Barracuda. We use the faster-accessing Velociraptor for gaming, so we install Steam on one of its partitions. Eventually, the Velociraptor begins to fill up, so we have to start evaluating how we’re using the space. For a game like Crysis, which will be accessing tons of data off the disk—fast—we definitely want to use the faster hard drive. However, for a game like Civilization 4, which is older and loads quickly pretty much no matter what, we could afford to move the game’s data over to the slower drive, clearing up a couple of gigabytes on the Velociraptor.
So how would we go about doing it? All we need to do is find the files we want to move. In our example, they’re located in D:\Games\Steam\steamapps\common\sid meier's civilization iv. We’ll move that folder somewhere on the 2TB drive, for instance to E:\Games\sid meier's civilization iv. Now, before starting up Steam again, we need to create a hard link to fill in the hole we left when we moved the folder. The command we’ll use to do that is:
mklink /J D:\Games\Steam\steamapps\common\sid meier's civilization iv E:\Games\sid meier's civilization iv
Now, when Steam looks for the Civilization 4 files, it will find them right where it’s expecting. However, the hard link is pointing it to data that’s actually on the 2TB drive. Using this technique, we can store our games wherever we like.
Managing Media Files Stored on a Network
One useful feature of symbolic links, as they are implemented in Windows Vista and later, is that they can point to other locations on a local network, as long as the other computer is also running a post-XP Windows operating system. This opens up a whole new set of uses for symbolic links.
For example, say you’ve got a home server set up to store all your media files, and you want to use iTunes to access your music from any other computer on your local network. iTunes allows you to choose where music is stored, allowing you to select your media server, but that’s not everything you need. You see, iTunes stores all the data it uses to make its big track index run smoothly in an XML file called a “library.” This library file is created automatically by iTunes; you cannot normally choose to access a library on a network drive. However, with mklink, this is easy.
Say you’ve mapped your media server’s music folder to drive letter M. All you would have to do to make your music library much more flexible is follow these steps:
1. Locate the folder containing the XML library files. By default, it’s usually found in username\music\iTunes.
2. Now, much like we did with the Steam game, we’re going to swap this file out with a mklink folder. So, first copy the contents of this folder to a folder on the network drive. You can name it whatever, we chose M:\shared music libraries.
3. Next, delete the folder from your local machine.
4. Finally, create the symbolic link. For iTunes, we don’t need a hardlink, so we’ll use the following command:
Mklink /D C:\Users\Username\Music\iTunes M:\shared music libraries
And that’s it. Now your music index files are saved on the server alongside the music files themselves. This allows you to get instant access to all these files from any computer on the network, by simply running the above mklink command on those computers.
XP HardLink
Submitted by say_no_to_holly... on Thu, 03/25/2010 - 6:49am
There's no reason to become a mascochist (Win7) to use HardLinks.
In XP download "Link Shell Extension"
http://schinagl.priv.at.nyud.net/nt/hardlinkshellext/hardlinkshellext.html
or upgrade to *nix
___
the Peoples Cube awaits
Backup & Directory Size
Submitted by William Lee on Mon, 11/09/2009 - 10:04pm
GREAT idea, but I got a comment and a question about this.
Comment: WinDirStat continues to work, but will report sizes including the files/directories you link rather than reporting their sizes as 0. RidNacs does more what I would expect, albiet not as pretty.
Question: I have Windows Home Server. Say I create a partition (e.g. G:), move some game files from my c: partition to the new g: partition and redirect from my C: partition to my G: partition using softlinks. At that point should I tell WHS to just backup my c: drive or backup both c: and g:? I.e. Do backup programs, specifically Windows Home Server's backup program, follow the links and backup the original files or do they just backup the links? If they backup the original files how would you go about doing a restore when your total data ends up exceeding the size of the physical drive due to the redirects?
dropbox/mozilla thunderbird
Submitted by clapp14 on Wed, 10/14/2009 - 9:54pm
Can you use symbolic links to sync mozilla thunderbird account between two computers using dropbox?
Hard v Symbolic
Submitted by Rasta Monsta on Sun, 06/28/2009 - 8:06am
The article states that a "hard" link was chosen in the Civ example, but that iTunes did not "need" a hard link, so "symbolic" link was chosen instead.
Why? This needs to be explained in greater detail.
Hard v Symbolic
Submitted by easye55 on Thu, 01/28/2010 - 11:14am
The major reason why they did not use a hard link (or junction) in the iTunes case was because they were referencing a directory on a network share. From my understanding of junctions, they can be used on different volumes on the same PC. However, can not be used to reference a remote directory.
Therefore, it isn't that they didn't "need" a hard link in this case, but rather, could NOT use a hard link. A symbolic link using the /D parameter was the only option.
Symbolic links are to point
Submitted by bruffstuff on Tue, 07/14/2009 - 6:11am
Symbolic links are to point you at a location which is mostly useful for file folders or if you want to only have to delete one copy of a file to free up space. Hard links would be chosen if you want to be able to update a specific file and not have the file content erased if the original file was deleted.
In other words Hard links point to data and symbolic links point to files. As the article stated, symbolic is a shortcut that any program can use since it is part of the OS.
To the original point, the chose a symbolic link because the data only had to be in one spot so a shortcut to the folder was the best solution. Most people want a song gone if they delete it and not to hang around because of a hard link at another location, which makes it easier to manage. You can also have another hard drive that can be used as a folder so you get to have the link to the folder and not take up space on the first drive.
bear with me, I'm slow
Submitted by thinsoldier on Fri, 10/30/2009 - 12:06pm
((Symbolic links are to point you at a location which is mostly useful for file folders or if you want to only have to delete one copy of a file to free up space.))
So that means if I have a SYMBOLIC Link on my C: drive pointing to a folder on my D drive and I delete the file C: then the real file on D: will also be deleted?
If that's the case then that means with HARD Links if I delete the HARD Link on C: the real file on D: will still exist?
Which means HARD Links are most like common shortcut (.lnk) files in that their deletion has no effect on the real file and the intentional deletion of the real file just makes the shortcut not work anymore.
Am I on the right track?
how to use with ssd?
Submitted by triclops41 on Thu, 05/28/2009 - 6:28pm
how would one best optimize using the steam example with one ssd and one hdd?
if the link from the hdd led to the folder in the ssd, would the files still be read at ssd speeds?
this may be obvious to some, but im wondering it the extra step that needs to be taken will negate the fast read speeds of the ssd if it first has to search the hdd for the link.
there was also a small
Submitted by dizzy1 on Mon, 05/18/2009 - 3:40am
there was also a small utility made by sysinternals to do the same thing
I've recently been playing a
Submitted by KaylaKaze on Wed, 05/13/2009 - 6:14pm
I've recently been playing a lot of NWN2 and was really annoyed by the horrible performance I was getting during loads. I read up on it and found out the game used temp data stored in the %TEMP% folder, which happens to point to my C:\ which is my slowest drive. I'm running XP 32-bit so I used Winbolic Link to create 2 junctions: one I junctioned the game's data, such as save games, modules, and overrides to a faster drive, and one to junction the temp data to a RamDrive (I have 6GB of RAM but since 32-bit can only use 4 GB of it, I use the space above 4 GB as a RamDrive). I get MUCH faster loads now.
Groan
Submitted by nightkiller on Wed, 05/13/2009 - 8:34pm
Kudos to MS for continuing to add useful functionality to their operating system.
After spending some thirty hours (!) installing Fedora Core 10 on a lousy P4 board where the updates to the OS took twice as long as the actual install (through yum), I know the kind of life I deserve. And it ain't one with Linux in it.
And as for the usual Linux whiners complaining about stealing ideas, why don't you investigate the history of minix and Torvalds?
Freetards.
You choose a flightless bird as a mascot and wonder why it doesn't take off?
Mistake?
Submitted by codepath on Wed, 05/13/2009 - 9:50am
The first sentence of the second paragraph under "What is a symbolic link?" reads:
"With a symbolic link, if the target directory or file is deleted, the link becomes non-functioning, as it points to a file that no longer exists."
I think it should read:
"With a shortcut, if the target directory or file is deleted, the link becomes non-functioning, as it points to a file that no longer exists."
Correct?
Very good
Submitted by carlosmessi on Wed, 05/13/2009 - 9:05am
I appreciate all good improvement even if they take them from an "open source system". Microsoft all the way, you are good and I'm with you. Thank you.
Something else that MS has stolen from the Unix and Linux world
Submitted by thefuzz4 on Wed, 05/13/2009 - 7:58am
This functionality has been around for a long time already in the Unix and Linux world. If your a Linux user just use ln -s <Source> <Target> and you don't need any other special switches whether it be a particular file or a directory. Way to go MS steal something that works great and try and beef it up as oh look what we just made up.
the linux world??
Submitted by almax on Wed, 05/13/2009 - 11:12pm
This "functionality" has been around since NT 3.1 and DOS 3.1
With commands like "SUBST" and "NET USE"BTW, Shouldn’t:
"If you’re a Linux user just use..."READ:
"If you’re a Linux user, just continue using your ripped off version of UNIX"
Erm, other than the GUI
Submitted by horzo on Wed, 05/13/2009 - 11:32am
Erm, other than the GUI front end, OS X is nothing but a Unix box. Does that mean Apple should be critisized for stealing an entire operating system?
Nothing wrong with re-using something that works.
Nice work Alex, another
Submitted by NAYRhyno on Wed, 05/13/2009 - 5:40am
Nice work Alex, another great how-to article.
___________________________
Game-Central.org
Sync Firefox Profiles?
Submitted by GrimResistance on Wed, 05/13/2009 - 3:17am
Can you use this with dropbox to sync your firefox profiles between computers?
Firefox and dropbox
Submitted by frankos72 on Wed, 05/13/2009 - 7:54am
I recommend the xmarks plugin. I have my bookmarks and saved password synced between 4 different computers. It doesn't take my cookies but that's not really important anyway. I've had to do two reinstalls since using xmarks and it makes getting your firefox back in working order a breeze.
I'm really start to take a strong liking to all these online sync programs.
I have xmarks and it is
Submitted by GrimResistance on Thu, 05/14/2009 - 2:48am
I have xmarks and it is really great, but I want my extensions too!
DOH!
Submitted by frankos72 on Wed, 05/13/2009 - 12:22am
Well as I was 1st setting it up it had great potential. THe file would link and everything appeared to syncronize from one spot to the other. Then I fired up the game. It doesn't matter how I link the files, COD will not recognize a link. In fact at one point I had linked the whole profiles directory. When I did so it would ask for my name at the start as if it were creating a new profile. But the name wouldn't stick and it would be asking again in short order. So , is there a trick to make this work? I guess I'm going back to the batch files. :(
Jev
What kind of link are you
Submitted by ddimick on Wed, 05/13/2009 - 7:40am
What kind of link are you creating?
I used a junction (/J) to relocate my entire C:\Users folder to a different drive for a long time now, works perfectly for me. Also use /J when I want to move a game to a different drive without reinstalling, also works great.
I've tried all 4 options
Submitted by frankos72 on Wed, 05/13/2009 - 7:52am
There is only one important file for the player profile it's the mpdata file. I've tried soft and hard links to it and soft and hard links to the directory structure. When I link to the directory, the changes show up fine in the OS so I know it's working. However none of these options work for the game. So, I guess I'm back to the batch file thing.
THIS ROCKS!
Submitted by frankos72 on Tue, 05/12/2009 - 11:34pm
Wow! I had already setup drop box after reading about it in your magazine this month. Then I was thinking about how I could use it to keep my profiles for Call of Duty current between my pc and laptop. I was going to write a couple little batch files for me to run before and after playing on each pc. Then I thought I remembered reading on here about 5 ways to tweak your dropbox. It might have been about gmail but anyway, I thought I'd look to see if there was something easier. You know closer to a set it and forget it option. Low and behold you have a story about mklink on the homepage of your website. I set this up and I'm completly amazed at how awesome it is. Now since I only play on one or the other PC at a time both will have my current profile all the time without me ever having to do anything but play and enjoy my game. THANK YOU MAXIMUM PC! YOU GUYS ROCK.
I do have one more tip for anyone using mklink. Since the file paths can be quite long, I just copied and pasted them into a command in a batch file. Then I exectued the batch file from the command line. I found this easier than trying to type those long paths perfectly without a typo.
Lastly, in your example of the /D command you left out the /D ;)
Thanks again!
Jev Vandegrift
Moore, OK
"I do have one more tip for
Submitted by sgaggerj on Fri, 07/31/2009 - 6:23am
"I do have one more tip for anyone using mklink. Since the file paths
can be quite long, I just copied and pasted them into a command in a
batch file. Then I exectued the batch file from the command line. I
found this easier than trying to type those long paths perfectly
without a typo."
Windows has the auto-complete feature in it's command prompts, so start typing a path and then hitt the tab key, it will auto complete the path - no typos!
If more than one matching path is found, keep using the tab to cycle through the available paths. It will also auto-quote long path names.
I find this easier if you know the path you want.
J Sgaggero
RI
-
Feature -
Feature -
How-To -
Feature -
Feature





