Microsoft DOS mklink command
Creates a symbolic link.
The mklink command is an internal command that is available in the below Microsoft operating systems.
MKLINK [[/D] | [/H] | [/J]] Link Target
|/D||Creates a directory symbolic link. The 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) of the new link.|
Note: The mklink command requires you to be in an elevated command prompt.
mklink /d \Docs \Users\Hope\Documents
The above example command would create a symbolic link called "Docs" to the \Users\Hope\Documents directory, even if the directory does not exist. If created successfully, you will see a message similar to the example shown below.
Symbolic link created for \Docs <<===>> \Users\Hope\Documents
Once the symbolic link has been created, using the dir command you can see any symbolic link in the directory listing of where the symbolic link was created. Below is an example of what the above symbolic link directory <SYMLINKD> would look like in the command line.
To get into the symbolic link directory, you would treat it like any other directory and use the cd command. To get into the Docs directory, you would type "cd docs" at the prompt.
How do I create a junction point?
Note: A junction point can only link to a local directory.
To create a junction point to a local directory perform the following command. As can be 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 has been created, using the dir command you can 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. For example, 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.
Tip: When you delete a symbolic link, you are just deleting the link to the file or directory that exists elsewhere on the computer does not get deleted.
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 a junction point.
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 is only removing the link or pointer and not the file or directory of where it is pointing. However, if you create a symbolic link or junction point to a directory and open that link or pointer and delete files in the directory, those files will be deleted.