mklink

On this page 7

mklink is a built-in Command Prompt command that creates symbolic links, hard links and directory junctions, special file system entries that make one path lead to a file or folder stored somewhere else. In Windows storage & file systems, it is the classic tool for redirecting paths without copying data, for example to move a large folder to another drive while applications keep using the original location.

The links that mklink creates are features of NTFS, implemented either as additional directory entries (hard links) or as reparse points that the file system follows when a program opens the path. Understanding which type to create is the main skill the command requires.

The mklink syntax is mklink [/D | /H | /J] Link Target, where Link is the new path and Target is the existing item. Note the order, which is the reverse of many Unix habits: the name being created comes first. Without a switch, mklink creates a file symbolic link.

The table below summarizes the four forms of the command and what each produces.

Command formCreatesTarget type
mklink Link TargetFile symbolic linkFile, local or remote
mklink /D Link TargetDirectory symbolic linkFolder, local or remote
mklink /H Link TargetHard linkFile on the same volume
mklink /J Link TargetDirectory junctionFolder on a local volume
mklink switches and the links they create

Because mklink is an internal command of cmd.exe, it does not exist as a separate program. In PowerShell the equivalent is New-Item with -ItemType SymbolicLink, Junction or HardLink, or the command can be invoked through cmd /c mklink.

Each link type works through a different NTFS mechanism, which explains its rules. A hard link is simply a second name for the same file record in the Master File Table, so both names are equal and the data disappears only when the last name is deleted. That is why hard links cannot cross volumes and cannot point to folders.

Symbolic links and junctions are reparse points: small records attached to an empty file or folder that tell the I/O manager to substitute another path. A symbolic link stores a path that can be relative or absolute and may point to network shares, while a junction stores an absolute local path and is resolved on the system that hosts it. Directory listings mark these entries with labels such as SYMLINK, SYMLINKD and JUNCTION.

The following comparison shows how the three link families differ in practice.

PropertySymbolic linkJunctionHard link
Applies toFiles and foldersFolders onlyFiles only
Cross-volumeYesYes, local onlyNo
Network targetsYes, policy dependentNoNo
Relative pathsSupportedNot supportedNot applicable
Privilege neededAdmin or Developer ModeNone beyond write accessNone beyond write access
If target is deletedLink becomes danglingLink becomes danglingData remains via the link
Comparison of Windows link types

Creating symbolic links requires the Create symbolic links user right, which Windows grants to administrators by default. Since Windows 10 version 1703, enabling Developer Mode allows standard users to create symbolic links from an unelevated prompt, which is why development tools increasingly rely on them. Junctions and hard links need only write access to the location of the new entry.

Following symbolic links is controlled separately by the symlink evaluation policy, viewable with fsutil behavior query SymlinkEvaluation. It defines whether links of four kinds are followed: local-to-local, local-to-remote, remote-to-local and remote-to-remote. By default remote-to-local and remote-to-remote evaluation is disabled, a protection against links on file shares that redirect clients to their own disks.

mklink is most valuable when software expects data at a fixed path that the administrator wants to change. The decision table below matches common goals with the appropriate link type.

GoalRecommended linkReason
Move a game or cache folder to another driveJunctionNo privileges, local volumes only
Point a config path to a synced folderDirectory symbolic linkSupports relative and remote paths
Share one large file between two foldersHard linkNo extra space on the same volume
Keep a stable path to a versioned toolJunction or symbolic linkRepoint without changing scripts
Link to a folder on a file serverDirectory symbolic linkJunctions cannot target UNC paths
Choosing a link type for common tasks

A typical relocation sequence is to close the application, move the folder to the new drive, then create a junction at the old path, for example mklink /J "C:\Data\Cache" "D:\Cache". Windows itself uses junctions for backward compatibility, such as the legacy Documents and Settings path that points to the Users folder.

Common mistakes and risks

Most problems with mklink come from misunderstanding what deletion and copying do to links. The table below lists frequent symptoms with their causes and fixes.

SymptomCauseFix
Error that the file already existsLink path already existsMove or rename the original first
Privilege not held errorSymbolic link right missingElevate or enable Developer Mode
Link works locally but not over a shareEvaluation policy blocks itReview SymlinkEvaluation settings
Backup contains data twiceTool follows linksConfigure the tool to skip reparse points
Target deleted unexpectedlyRecursive delete followed a linkRemove links with rmdir first
Frequent mklink problems
  • Remove a link, not its target. Use del for a file symbolic link and rmdir without the /S switch for a directory link or junction; both remove only the link.
  • Avoid link loops. A junction pointing to its own parent can trap recursive tools in endless traversal.
  • Treat links as a security surface. Attackers abuse junctions and symbolic links in link-following attacks against privileged services, so writable folders used by such services need careful permissions.

Understanding it simply

mklink makes signposts in the file system. A signpost looks like a normal file or folder, but when a program opens it, Windows quietly sends the program to the real location somewhere else.

This lets you move a big folder to a second drive while programs still find it at the old address. Deleting a signpost removes only the signpost, not the files it points to, unless it is a hard link, which is really a second name for the same file.

Applied in practice

A video editor works on a laptop with a 512 GB system drive that is nearly full. Her editing software stores about 180 GB of render cache in a fixed folder under her user profile and offers no setting to change it. She attaches a fast 2 TB external SSD that stays connected at her desk.

She closes the software, moves the cache folder to the SSD and runs mklink /J from the old location to the new one. No administrator prompt is needed because a junction requires only write access. The software starts normally, writes new cache files straight to the SSD and never notices the change. The outcome is about 180 GB of reclaimed space on the system drive in a few minutes, and she can undo it later by deleting the junction with rmdir and moving the folder back.