Sensational Symlinks in Windows

Let me guess: you’ve heard of symbolic links (also known as symlinks) but you’re not sure what to use them for.

In this guide I’ll simplify symlinks and show you some practical uses for this often misunderstood Windows feature.

Think of a symlink as a pointer to another folder.

Just as a symbol is something that represents something else so a symlink is just a file or folder that represents another file or folder.

If a symlink were a person he would be the most self-effacing person in the world because his entire purpose in life is to point you to something other than himself.

But what’s the point (pun intended)?  Why would anyone use a symlink?

Salient Symlinks

Some applications expect files to reside in specific folders.

If those files don’t live there you usually have to:

  • Move all the files into the folder the application expects
  • Or, reconfigure the application to search for your files in a different folder.

Symlinks can obviate both conundrums by making a folder in one place function as if it were really in another place.  Initially this may seem no different than a shortcut.

Good observation – but you’re only partially right.

Symlinks come in two categories soft and hard.  The former, soft symlinks, are just boring shortcuts.  Clicking a soft symlink whisks you away to destination folder and is functionally identical to a shortcut.

Conversely, hard symlinks are a different beast because they make it look like the file or folder is physically located at the symlink.

Sound confusing? It doesn’t have to be.  Believe it or not you’ve already been using symlinks for years.

Check this out:

In Windows 8 or 8.1 you can press the Windows Key + x + a to open an elevated command prompt (a prompt with Admin privileges)

Open the command prompt and type the following  command:

dir /AL /S c:\ | more

Viewing all symlinks in Windows 8.1

There’s a lot of information here but it can be sliced into four columns:

  • Date
  • Time
  • Reparse Point (fancy term for Symlinks)
  • Folder and Target

Do you see all those  <JUNCTION> and <SYMLINKD> attributes in the 3rd column from the right?  Those are all common symlinks.  You probably see “Documents”, “Start Menu” and others.  The actual folder and target displays in the last column.

Let me show you how to construe the table:

In the screenshot above the first entry shows I have a <JUNCTION> named “Documents and Settings” that actually points to “C:\Users”.  So what’s up with that?

You’re actually seeing vestiges of Windows XP (it just won’t die).  It’s like looking back into the tunnel of Microsoft time.  “C:\Documents and Settings” is a  left over compatibility thing from the Windows XP days.

In Windows XP all your documents and settings were saved in C:\Documents and Settings but with the inauguration of Windows Vista, Microsoft wisely bifurcated user application data between C:\Users and C:\ProgramData. So C:\Documents and Settings is a nothing folder, it’s just a symlink to where your real user preferences live.

Wait, is a Junction a Symlink or what?

Technically “C:\Documents and Settings” is actually a junction not a symlink but since we’re only talking about the local file system you can think of junctions and symlinks as being identical.

If you’re a developer or experienced geeks reading this article then you know junctions are technically different because they are have special nuances for remote connectivity but I won’t get into a pedantic discussion about that right now.  As far as your local computer (and you) are concerned – it’s basically the same thing.

Savoring Symlinks

Okay, okay – you probably won’t savor them but at least you can squeeze delicious utility out of them.

One good reason to use symlinks is so you can store media such as movies, photos and songs on a larger external drive and then create a directory symlink from the default location.  Hard symlinks will make it appear as if your media libraries are living on your local system even though they actually live on a capacious external drive.

You can also use symlinks to sync folders that live outside their default locations. Let’s explore the first benefit together.

I love music

I’m a huge audiophile.

I’ve been a music head since high school and have a variegated library of songs.

I have an eclectic taste for everything from Industrial to Indie.

Hip-hop to House.

Oldies to Opera (seriously)

I can appreciate almost any genre of music as long as the quality is pristine (preferably lossless) – but I can’t get into Country music even though my wife loves it – I just can’t deal it – perhaps I’m not cultured enough.

Say hi to my iTunes library

Anyway, I have hundreds of high-quality songs hanging out in my external drive D:\Music but iTunes expects them in C:\Users\vhudson\Music\iTunes Media.

Without symlinks I would have to move my entire library to C:\Users\vhudson\Music\iTunes Media; however, by entering a simple command I can trick iTunes into thinking all my D:\Music songs actually live in C:\Users\vhudson\Music.


Keep in mind the symlink folder name can’t already exist so I needed to delete  C:\Users\vhudson\Music\iTunes Media.

Why?

Because you can’t have a normal directory and a symlink directory with the same name.  Windows can’t easily distinguish between the two.

Also, never create a symlink to another symlink.  It will cause the universe to collapse and you’ll wish you never woke up.  Going symlink to symlink in Windows will seriously screw up your computer because it’ll get caught in an interminable loop.

Think of symlink to symlink like pressing the red button on the nuclear sub.


That being said – let’s kick open the command prompt to get started.  Hit the Windows Key, type cmd and press Ctrl Shift + Enter.

We’re going to use the mklink command to create the symlink.

The syntax is pretty straightforward.

mklink syntax

We’re going to create a hard link and use D:\Music as the source link folder.

Here’s what I entered:

mklink /J "C:\Users\vhudson\Music\iTunes Media" "D:\Music"

I put quotes around the folder path for readibility:

Creating a symlink in Windows 8.1

Now if you flip open Explorer you’ll see a folder that looks like a normal shortcut in the sense that there is a little arrow in the bottom right corner of the folder.  But if you click it you’ll teleport your mouse to the target path which in my case – is my D:\Music folder.

If you make a mistake when creating symlinks you can always press Ctrl + z in Explorer to step out of the changes.  Or even easier, you can just right click the Symlink folder in Explorer and hit the delete key.

Easy enough right?

I’d love to hear how you use symbolic links on your PC.  Share the experience in the comments.

About

Connect with Vonnie on Twitter

Posted in Windows, Windows 7, Windows 8, Windows 8.1 Tagged with: