Symbolic Links in Windows

I like to spend most of my time in OS X. I have nothing against Windows. All operating systems are nothing more than tools, and you don’t here people yelling at each other in Home Depot about Black & Decker v Dewalt so why is it that we get so up in arms about Apple v Microsoft?

All things aside, I have never been fond of the whole “Shortcut” thing that windows has. It sounds good in concept, create a shortcut on my desktop (or wherever) so I don’t have to go dig through 30 directories worth of crap to find that one folder where I need to delete that 1 file. Just make a shortcut to that folder so you can get there quickly. But here’s where things break down to me.

Let’s say you have a file F:\some\folder\somewhere\foo\bar.txt and we want to put a shortcut so that I can type in vim C:\foo\bar.txt. Shortcuts won’t do this for you. A shortcut in windows is not just a link to a folder/file it’s a *.lnk file. So when you try follow it in cmd, you’re out of luck.

In Unix based operating systems, the problem is solved by having Symbolic Links. Your symbolic link acts just like any other file/folder that just references another file/folder. It’s a wonderful system and I have no idea why anyone would opt for a shortcut that works any differently. For years I never understood why Windows doesn’t have them – Turns out, they do… Sort of.

Linking to Files in Windows

While Unix has Symbolic and Hard Links, that can link to either files or folders, Windows does not. There are some rules that must be observed for linking in Windows.

  • Junctions and Hard Links are only supported on NTFS formatted hard drives.
  • Hard Links can only be made to files.
  • Junctions can only be made with directories.
  • Symlinks can be made to files or folders.
  • Symlinks will show the size of the symlink, not the size of the file linked to.
  • When updating a file with a Hard Link, only the Hard Link used to open the file will have it’s size (or attributes) updated. No other Hard Links to the file will be updated.
  • Junctions, Hard Links and Symlinks must be made in the command line, there is no GUI interface (unless you download a 3rd party application)

Symlinks and Hard Links are similar. Symlinks show up in the GUI as a shortcut, but they do not end with the lnk extension. Hard links will prevent the referenced file from being deleted if any other hard reference tries to delete the file – Symlinks will not.

Junctions are how you link to a directory. Junctions do not keep their referenced folder from being deleted. If the referenced folder gets deleted, you have a broken Junction. I haven’t yet determined what the difference between Junctions and Directory Symlinks.

Creating Links in Windows

Creating links is all done through the command line with the mklink command.

Leave a Reply

Your email address will not be published. Required fields are marked *