Mklink command
The mklink command creates a symbolic link through the Windows command line.
Availability
Mklink is an internal command that's available in the following Microsoft operating systems.
Mklink syntax
MKLINK [[/D] | [/H] | [/J]] Link Target
/D | Creates a symbolic directory link. The default is a symbolic file 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) of the new link. |
Mklink examples
The mklink command requires you to be in an elevated command prompt.
mklink /d \Docs \Users\Hope\Documents
The example command above would create a symbolic link called Docs to the \Users\Hope\Documents directory, even if the directory does not exist. If the link is successfully created, a message similar to the one shown below is displayed.
Symbolic link created for \Docs <<===>> \Users\Hope\Documents
Once the symbolic link is created, using the dir command lets you see any symbolic link in the directory listing of where it was created. Below is an example of what the previous symbolic link directory, <SYMLINKD>, would look like in the command line.
To get to the symbolic link directory, you would treat it like any other directory and use the cd command. To get to the Docs directory, type "cd docs" at the prompt as if it was a directory.
How do I create a junction point?
A junction point can only link to a local directory.
To create a junction point to a local directory, perform the following command. As seen, we are using the /j switch instead of the /d switch.
mklink /j example backup
If created successfully, you will see a message similar to the example shown below.
Junction created for example <<===>> backup
Once the junction is created, using the dir command lets you see any junction in the directory listing of where the junction was created. Below is an example of what the above junction directory <JUNCTION> would look like in the command line.
How do I create a symbolic link or junction to a directory with a space?
If the file or directory you want to link or point to contains a space in its name, it must be surrounded with quotes. In the example below, we are creating a symbolic link to the "c:\program files" directory from the current directory.
mklink /d files "c:\program files"
How do I delete a symbolic link?
To delete a symbolic link, treat it like any other directory or file. If you created a symbolic link using the command shown above, move to the root directory since it is "\Docs" and use the rmdir command. If you created a symbolic link (<SYMLINK>) of a file, to delete a symbolic link use the del command.
How do I delete a junction point?
A junction point is only going to be a directory, so you should only need to use the rmdir command to remove it.
Will deleting a symbolic link or junction point delete the linked files or directory?
No. When you delete a symbolic link or a junction point, it's only removing the link or pointer and not the file or directory to which it's pointing. However, if you create a directory symbolic link or junction point and open that link or pointer and delete files in the directory, those files are deleted.