Windows Has Symbolic Links And It’s Called mklink

Windows Has Symbolic Links And It’s Called mklink

Get Social!

A symbolic Link is a reference to a file which is stored in another location to make a file or folder accessible from that location. For example, if you have a directory in c:\Users\James and wanted to make that accessible from c:\James you could create a symbolic link of c:\Users\James to the location c:\James which would mean anything stored in c:\Users\James such as test.txt would be accissible from c:\James\test.txt.

This has been available in Linux since the dawn of time and is one of the common file system functions. It’s used as standard by Apache2 on Ubuntu to enable or disable site config files. What you might not know, however, is that symlinks are available on Windows and have been for some time. In Windows symlinks are created using a command line application called mklink.

mklink-command-prompt

A link works exactly like the object is actually in that location; it’ll show in Windows Explorer, and CMD prompt and all Save As dialogues.

Create an mklink

To create a directory link you’ll need to open a command prompt and use the mklink command as below with your values substituted.

mklink /j [linkname] [target]
  • [linkname] is the new object that will be created on the file system to point to your [target] location.
  • [target] is the file system location of the file or directory that you would like to link to.

You can think of this process in a similar way to creating a Windows shortcut. The [linkname] is the place you will save your shortcut and the [target] is the place your shortcut will take you when you double click it. Remember an mklink is not the same as a shortcut because an mklink will make the target location look like it’s physically available at the link location where a shortcut will simply send you to the target location when clicked.

Delete an mklink

mklink-folder-exampleChecking if a folder is a link or a regular file system object is quite easy. If you look at it in Windows Explorer will show a small arrow on the icon, much like a shortcut, or you can look at it using dir in a Command Prompt similar to below:

c:\Users\James>dir

14/07/2015  19:37  <JUNCTION> my-link [C:\Users\James\Desktop\my-link-source]

You can see that the directory link called my-link is referenced as <JUNCTION>.

Deleting the mklink is then done in the same way as deleting any other filesystem object – simply delete it using Windows Explorer.


Visit our advertisers

Quick Poll

Do you use ZFS on Linux?

Visit our advertisers