Last Updated: September 29, 2021
·
14.17K
· marcelo

Symbolic links in windows

Recently I found out that symbolic links exist in windows operating system (supported in windows vista and above) using the following command:

mklink

For those who are not familiar with the concept of the symbolic links (or hard links), i'll just say i'ts like a shortcut to a file or a folder managed by the file system. so after creating a symbolic link from a file or a folder to another location you could access it from the new location the same as you would from the original location.

Saying that, if you execute it without any argument this what you'll get:

C:\>mklink
Creates a symbolic link.

MKLINK [[/D] | [/H] | [/J]] Link Target

        /D      Creates a directory symbolic link.  Default is a file
                symbolic link.
        /H      Creates a hard link instead of a symbolic link.
        /J      Creates a Directory Junction.
        Link    specifies the new symbolic link name.
        Target  specifies the path (relative or absolute) that the new link
                refers to.

Seeing this we have four types of links in windows:

no flag/default symbolic link to a file:

mklink d:\link-name c:\original-file

/D same as "no flag" but for a folder:

mklink /D d:\link-folder-name c:\original-folder

/H hard link to a file:

I won't expand that subject too deeply, i'll just say that the main limitation of a hard link is that it can only be created in the same volume.

mklink /H d:\link-name c:\original-file

/J directory junction:

A term I wasn't familiar with, from what I could tell the final result of using it is exactly the same as with a normal symbolic link to a folder.

note: the advantage I found when using the "directory junction" instead of a normal symbolic link to a folder, is that when mounting a cifs share that has a symbolic link in my ubuntu machine, the only way I could access it, was with that flag.

mklink /J d:\link-folder-name c:\original-folder

resources: