Using Symlinks in Windows for Fun and Profit

By Will Smith

Symbolic links let you create a connection between two places on your computer's filesystem or even network shares. Use them to perfect your storage schemes.

You may have heard of symlinks, or symbolic links, before, but weren't quite sure what they're good for. Symlinks are kind of like a wormhole in your filesystem--they're placeholders on the drive that redirect applications to whatever folder or file you point them at. They're especially handy when an application, like iTunes, doesn't allow you to configure the location it expects to find your music. So, instead of moving all your music to the folder that iTunes wants, you can simply create a symlink from the folder that iTunes expects to the folder that you prefer to store your music in. To your programs, a symlink is indistinguishable from the actual files in question.


Symlinks work best in Windows Vista and Windows 7 (OSX also includes symlinks, but we'll talk about them later). While they're lightly supported in Windows XP, they aren't quite as transparent to apps as in the later OSes, and we haven't tested them in XP, so your mileage may vary.

To create a symlink, open your command prompt--the quickest way is to press the Windows key and type cmd at the prompt--and browse to the folder you want to create a symlink in using  basic DOS commands. Once you're there, you'll use the mklink command to create your link. The basic structure of the command is mklink <arguments> <symlink> <targetoflink>. I'll break that down for you.

There are several arguments that mklink can take, but you'll probably only use two. The most useful command is the /j option, which lets you make a symlink to a directory. This will make the linked directory appear in a second location on your hard drive. You may also create a hard link to an individual file, rather than a directory by using the /h argument. The third option, /d, creates a soft link, which is more akin to a shortcut. The difference between the soft link and the hard link is that the file you hard link to appears to be stored in the link's location on the drive, while the soft linked file appears to be in its original location. If you want to symlink a directory, you must use the /j option.

In place of <symlink>, you'll need to enter the name you want for your symlink. If you're symlinking a directory, it's important that there not be a directory or file with the same name. So, if you're replacing a folder that already exists, you'll need to copy it someplace else before you can create the symlink. 

The <targetoflink> is the folder or file that you want to create the link to. You need to use the complete path to the file here, so if any of the folder names have spaces, you'll want to enclose the entire path in quotation marks.


mklink /j "c:\users\Will\Music\iTunes\iTunes Music" d:\Music\ - This line makes a symlink that redirects from the folder c:\users\Will\Music\iTunes\iTunes Music to the Music folder on my second hard drive. This type of use is especially handy if you have a small main hard drive and a larger secondary drive.

mklink /h "c:\users\Will\AppData\Roaming\AppName\settings.xml" "c:\users\Will\Dropbox\settings.xml" - This line builds a symlink between a specific settings file in your user profile directory and the same file in your Dropbox (Make sure you copy the file to your Dropbox first, or it will be overwritten!). You can use this to sync your settings across multiple computers.    
 
To delete a symlink, just browse to its location in Explorer, right click it, and press delete.
 

Beware: Danger Ahead 

There are a few things you shouldn't do, because they'll wreak havoc on your file system. There are two main rules. Don't create symlinks inside symlinks and don't create symlinks to symlinks. Doing either of these things can create loops inside the filesystem, which causes real problems for things like virus scanners.