MS-DOS and Windows command line mklink command

Updated: 01/31/2019 by Computer Hope
mklink command

The mklink command is used to create a symbolic link through the Windows command line.

Availability

Mklink is an internal command that is 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

Note

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, you will see a message similar to the one shown below.

Symbolic link created for \Docs <<===>> \Users\Hope\Documents

Once the symbolic link is created, using the dir command you can 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.

Symbolic Link

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 as if it was a directory.

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 is 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.

Windows junction point

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 is only removing the link or pointer and not the file or directory to which 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.

Additional information

  • See our symbolic link page for further information on this term.
  • See our junction page for further information on this term as well as information about the differences between a symbolic link and junction point.