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!
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.
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:
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:
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:
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.
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