This is a guest post from Joseph Moody at DeployHappiness.com. More information on Joseph is included in his author box following this post. Thanks, Joseph!!!
Symbolic Links are the most powerful file server tool that you aren’t using. Occasionally called symlinks, these advanced shortcuts allow you to perform some serious smoke and mirrors when accessing data.
Consider the following common scenarios:
- An application checks for data in a certain location. You would rather store that data elsewhere.
- Old software needs to write to C:\. You want it to write to %ProgramFiles%.
- You wish to move data to a new share but don’t want to break existing shortcuts
- You need an easier way to migrate paths from standard shares to DFS Namespaces
In all of these cases, symbolic links provide a solution.
Creating Your First Symbolic Link
If you have ever installed Windows Vista or higher, you’ve created a symbolic link. That hidden Documents and Settings shortcut in the root of C: is technically a symbolic link. It refers to C:\Users for compatibility purposes.
Making a symbolic link is easy. To create one, you will use the mklink command. Fire up an administrative command prompt and type mklink /? to see the syntax.
As an example, let’s create a symbolic link that redirects a folder from the root of C: to %ProgramFiles%. First, create a folder in C:\ named data. Populate this folder with a file or two. This is your source folder – the folder that you will be moving.
Cut this folder from C:\ and move it to %ProgramFiles%. In your administrative command prompt, type: mklink /D C:\Data “%ProgramFiles%\Data”
You should now see a shortcut in C: named Data. Its type though should read file folder. When sorted by name, it should also appear as a folder (one advantage over shortcuts).
If you open the Data folder, you should see the exact content that you moved over to %ProgramFiles%. As a test, open a second Explorer window and navigate to %ProgramFiles%\Data. Create a new text document – it should appear in C:\Data. Like Magic!
How Will You Use Symbolic Links?
The mklink command supports way more than we just showed. At times, you may have to use a directory junction, create hard links, or specify relative target paths.
Working with symbolic links is the fastest way to master these advance parameters. If you want to learn more about symbolic links, check out these three links:
- Inside the Windows Vista Kernel: Scroll down to File-Based Symbolic Links – written by Mark Russinovich (who really knows his stuff)!
- Creating Symbolic Links: A more detailed explanation of symbolic links on MSDN. Explains concepts with symbolic Links.
- Hard Links and Junctions: An explanation of hard links and junctions – written for developers but useful knowledge.
Latest posts by Joseph Moody (see all)
- How Symbolic Links Make Server Migrations Much Easier - December 11, 2014