|

How To Use The Mklink Command In Windows (2027)

Mklink creates a link, which is a second path that points to an existing file or folder, from Command Prompt.

The basic form is mklink , with the new link name first and the existing item second.

This guide follows Microsoft’s mklink reference and its file-linking pages, so each link type below is documented.

Table of Contents

Mklink quick answers

I want toType this
Link to a file (symbolic link)mklink
Link to a folder (symbolic link)mklink /d
Make a hard link to a filemklink /h
Make a directory junctionmklink /j
Remove a folder linkrd
Remove a file linkdel

Replace the placeholders with real paths, and keep the link name first.

Open Command Prompt as administrator

  1. Press the Windows key and type cmd.
  2. Right-click Command Prompt and choose Run as administrator.
  3. Type your mklink command and press Enter.

Microsoft’s PowerShell documentation says creating a symbolic link on Windows requires elevation as administrator, unless Developer Mode is on in Windows 10 build 14972 or newer.

The steps for an elevated window are in how to open Terminal as administrator.

The mklink syntax

Microsoft gives the syntax as mklink [[/d] | [/h] | [/j]] .

The link is the name of the new link, and the target is the path, relative or absolute, that it refers to.

Without a type switch, mklink creates a file symbolic link.

Mklink switches at a glance

SwitchWhat it creates
NoneA file symbolic link, which is the default.
/dA directory symbolic link.
/hA hard link instead of a symbolic link.
/jA directory junction.

Symbolic link, hard link or junction

Link typePoints toLimits Microsoft documents
Symbolic linkA file or a directoryThe target can be relative or absolute, and a link can point to a target that does not exist.
Hard linkA file onlyCannot reference directories, or files on a different volume.
JunctionA directory onlyCan link directories on different local volumes, but not mapped network volumes.

Microsoft describes a hard link as more than one path referencing a single file on the same volume.

It describes a junction as a link to a separate directory, and notes that junctions are implemented through reparse points.

Create a file symbolic link

  1. Open an elevated Command Prompt.
  2. Run mklink C:\Links\notes.txt C:\Docs\notes.txt with your own paths.
  3. Open the new link to confirm it shows the contents of the target.

The paths in the example are placeholders, and the target here is the existing file.

Create a folder symbolic link

Microsoft’s own example is mklink /d \MyFolder \Users\User1\Documents.

That makes a link named MyFolder that opens the Documents folder, because the /d switch marks it as a directory link.

Create a hard link

Microsoft’s example is mklink /h \MyFile.file \User1\Documents\example.file.

Any change made to a hard-linked file is instantly visible through every link that references it.

Microsoft also says you can delete hard links in any order, whatever order they were created in.

Create a directory junction

Use mklink /j when you want a folder link between local volumes.

Microsoft says a junction can link directories located on different local volumes on the same computer.

A junction cannot point at a file or at a mapped network volume.

Relative and absolute targets

Microsoft says absolute links specify each portion of the path, while relative links are determined relative to where the link sits.

Target formResolves to
..\folderRelative to the parent directory.
folderRelative to the current directory.
\Windows\System32Relative to the root of the current drive.
A path with a device nameTreated as an absolute link.

What a hard link cannot do

ExampleAllowed?
A file linked to another file on the same volumeYes.
A directory linked to another directoryNo, hard links cannot reference directories.
A file on C: linked to a file on D:No, they cannot reference files on different volumes.
A file linked to a file on a mapped network driveNo.

If a hard link fails for one of those reasons, use a symbolic link or a junction instead.

How changes show up through a hard link

Microsoft says the attributes of the file are reflected in every hard link to it.

However, the directory entry size and attribute information are visibly updated only at the link through which the change was made.

Microsoft’s example is clearing the read-only flag on one link, which leaves the other links still showing read-only.

Create symbolic links without administrator rights

Microsoft says Windows 10 build 14972 or newer with Developer Mode enabled no longer requires elevation to create symbolic links.

Its API documentation adds that Developer Mode must first be enabled on the machine for the unprivileged option to work.

Without Developer Mode, run the command from an elevated window.

Which link type to use

  • Use a symbolic link when the target can be a file or a folder, or when you want a relative path.
  • Use a hard link when two paths on the same volume should reference one file.
  • Use a junction when you need a folder link across local volumes.

Remove a link without deleting the target

Microsoft’s example removes a directory link with rd \MyFolder and a file link with del \MyFile.file.

Use rd on the folder link itself, never on the target path.

Microsoft’s API documentation says file links are deleted with file delete calls and directory links with directory removal calls.

The PowerShell alternative

PowerShell’s New-Item cmdlet takes an -ItemType of SymbolicLink, Junction or HardLink.

Microsoft’s example is New-Item -ItemType SymbolicLink -Path .\link -Target .\Notice.txt.

Before PowerShell 6.2, the target had to be a fully qualified path.

Limits to know about

  • Microsoft says a path can contain a maximum of 63 reparse points, and symbolic links are reparse points.
  • A symbolic link can point to a target that does not exist, and Windows does not check when you create it.
  • Opening a link whose target is missing returns a file not found error.
  • Microsoft notes that the Cluster Shared Volume file system does not support soft links or other reparse points.

Related guides

To copy folders and files with a command, see the Robocopy guide, and for another storage task see how to mount an ISO file.

For another command-line task, see the reg add guide.

Official sources

The switches and examples come from Microsoft’s mklink reference.

The link type limits come from Microsoft’s hard links and junctions page, and the target rules come from the CreateSymbolicLinkW reference.

The PowerShell details come from Microsoft’s New-Item reference.

Leave a Reply

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