CodeSteps

Python, C, C++, C#, PowerShell, Android, Visual C++, Java ...

Windows – MKLINK – How to create a Symbolic link?

Windows provides a mechanism to allow you to create Symbolic link to your File, Program or to a Folder. Symbolic links are the special files (NOT Shortcuts) points to another source file or directory.

MKLINK command is useful to create the Symbolic links in Windows.

Create a Symbolic link

To create a Symbolic link, you need to provide the Link name and the File or Directory path as arguments to this command. For example, to create a Symbolic link to the “sample.txt” file; you can write the command like below:

c:\>mklink l sample.txt
symbolic link created for l <<===>> sample.txt

If the symbolic link name already exists; you will see below message.

Cannot create a file when that file already exists.

When you list the files through DIR command, the symbolic link entry will display like below:

2011/06/08  05:15 PM    <SYMLINK>      l [sample.txt]

Observe that, DIR command displays both Symbolic link and associated file name.

Symbolic link vs Hard link (Soft link vs Hard link)

When you delete or rename the source file for which the Symbolic link was created; the link will be no longer valid. The link will exists but corrupted; as it’s source was deleted.

How to strongly bound the Symbolic link and the Target source? That is where Hard link comes. By default MKLINK command create a Symbolic link (soft link). To create a hard link, you need to pass “/H” argument to this command. For example, below command creates a hard link:

c:\>mklink hl Personal
symbolic link created for hl <<===>> Personal

Hard links are hard bounded to the Source. When you rename the source file or folder; the associated hard link automatically points to the new renamed file. Whereas in symbolic link, the link will be broken when you rename or delete the sources.

When you delete the source file or folder; the associated hard link still valid and you can open the file or folder through the hard link. That means, Windows internally takes a special care when dealing with Hard links.

Be on learning path always!

// Malin

Windows – MKLINK – How to create a Symbolic link?

Leave a Reply

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

Scroll to top