mklinkMKLINK Command Guide - Create Symbolic Links and Junctions in Windows
Learn how to use the mklink command to create symbolic links, hard links, and directory junctions in Windows. Includes syntax, examples, and best practices for file system linking.
The mklink command is a Windows Command Prompt utility that creates symbolic links, hard links, and directory junctions, allowing you to create file system pointers that reference other files or folders. Use /D for directory symbolic links, /H for hard links, and /J for directory junctions—each serves different linking needs.
Whether you're organizing project files across drives, creating application compatibility layers, migrating data without moving files, or setting up development environments that require specific directory structures, mastering mklink gives you Unix-like linking capabilities directly in Windows. System administrators and developers rely on this command for flexible file system organization, legacy application support, and efficient storage management.
This comprehensive guide covers mklink syntax, all three link types (symbolic, hard, junction), practical examples for common scenarios, troubleshooting tips, related commands, and frequently asked questions. By the end, you'll confidently create and manage file system links from the command line.
What Is the Mklink Command?
The mklink command creates file system links—pointers that redirect access from one path to another. Windows supports three link types:
- Symbolic link (/D for directories) – A transparent pointer; the link appears as the target. Works for files and directories. Requires Administrator privileges.
- Hard link (/H) – Multiple directory entries pointing to the same file data. Files only; both paths share the same inode. No admin required.
- Directory junction (/J) – Legacy directory-only link. Compatible with older Windows; no admin required for creation.
Symbolic links are the most flexible—they can point across drives and to non-existent targets. Hard links are efficient for files on the same volume. Junctions work without elevation and are useful for directory-only scenarios.
The command runs in Command Prompt (CMD) and requires Administrator privileges for symbolic links. Available in Windows Vista and later, including Windows 11, Windows 10, and Windows Server editions.
Mklink Command Syntax
The basic syntax for the mklink command is:
mklink [[/D] | [/H] | [/J]] Link Target
Parameters and Switches
| Parameter | Description |
|---|---|
/D | Creates a directory symbolic link (default without /D is file symbolic link) |
/H | Creates a hard link instead of a symbolic link |
/J | Creates a directory junction |
Link | The path and name of the new link to create |
Target | The path (relative or absolute) that the link refers to |
If you omit all parameters, mklink displays its help. The link path must not exist; the target path should exist for hard links and junctions.
Link Types Explained
Symbolic Link (File)
Creates a file that transparently redirects to another file:
mklink link.txt C:\Data\original.txt
Accessing link.txt reads/writes original.txt. The link can span drives.
Symbolic Link (Directory) – /D
Creates a directory that points to another directory:
mklink /D C:\LinkDir C:\Target\Folder
C:\LinkDir appears as a folder containing the target's contents. Requires Administrator.
Hard Link – /H
Creates an additional name for the same file data:
mklink /H duplicate.txt original.txt
Both paths reference the same file. Deleting one does not delete the other until both are removed. Same volume only.
Directory Junction – /J
Creates a directory pointer (legacy junction):
mklink /J C:\Junction C:\Target\Folder
Similar to directory symbolic link but works without Administrator. Target must exist and be absolute.
Examples
Create a File Symbolic Link
Point a shortcut file to an existing document:
mklink report.docx C:\Archive\2024\Q1\report.docx
The link report.docx in the current directory opens the archived file. Useful for accessing files in deep directory structures without copying.
Create a Directory Symbolic Link
Map a development folder to a standard location:
mklink /D C:\Dev C:\Users\John\Projects\Active
Applications expecting C:\Dev will find the project files. Run Command Prompt as Administrator.
Create a Directory Junction
Create a junction without admin rights:
mklink /J C:\Shortcut C:\Program Files\LongApplicationName\Data
Access C:\Shortcut instead of the long path. Useful when symbolic links require elevation.
Create a Hard Link
Create an alternate name for a file:
mklink /H backup.dat original.dat
Both names point to the same data. Saves disk space when you need multiple references to one file.
Link to a Network Path
Symbolic links can point to UNC paths:
mklink /D C:\NetworkShare \\Server\Share\Folder
Requires Administrator. The link appears as a local folder.
Use Relative Paths for Portability
Create links using relative targets for script portability:
mklink config.ini ..\Shared\config.ini
The link resolves relative to its location. Useful in deployment scripts.
Multiple Links for One Target
Create several links to the same folder:
mklink /D C:\Docs C:\Users\Public\Documents
mklink /D D:\Docs C:\Users\Public\Documents
Different drive letters can point to the same content.
Link in Batch Script
Automate link creation:
@echo off
mklink /D C:\Projects C:\Dev\ActiveProject
mklink C:\Config\settings.ini C:\Templates\default.ini
echo Links created.
Run the script as Administrator for symbolic links.
Common Use Cases
-
Development environment setup – Create
C:\Devpointing to your project folder for consistent paths across tools and scripts. -
Application compatibility – Redirect legacy apps expecting specific paths (e.g.,
C:\OldApp\Data) to new locations. -
Multi-drive organization – Link folders across drives so related content appears in one place without copying.
-
Backup and sync – Use hard links for backup tools that support deduplication; multiple links share one copy of data.
-
Portable applications – Create links so portable apps find their data in the expected locations on different machines.
-
Version switching – Point
C:\CurrentVersionto different version folders and switch by recreating the link. -
Short path aliases – Replace long paths like
C:\Program Files\VeryLongName\DatawithC:\AppDatavia junction. -
Shared resources – Link common config or template files into multiple project directories.
-
Migration without move – During migration, create links so old paths still work while data lives elsewhere.
-
Docker and WSL – Create links to expose Windows paths to WSL or container workflows.
-
Testing and staging – Point test configs to production-like paths without duplicating data.
-
Library consolidation – Use junctions to make scattered library folders appear under one root.
Tips and Best Practices
-
Run as Administrator for symbolic links – Right-click Command Prompt and select "Run as administrator" when creating file or directory symbolic links.
-
Use absolute paths for junctions – Directory junctions require absolute target paths; relative paths may fail.
-
Verify target exists for hard links – Hard links require the target file to exist on the same volume.
-
Avoid circular references – Do not create links that point back to themselves or form loops.
-
Delete links, not targets – Use
rmdirfor directory links anddelfor file links; this removes the link, not the target. -
Check link type before deletion – Use
dir /ALto list symbolic links and junctions before removing them. -
Backup before bulk operations – When creating or removing many links, verify paths to avoid mistakes.
-
Use junctions when admin is unavailable – If you cannot elevate, use
/Jfor directory links. -
Document link purposes – In scripts, add comments explaining why each link exists for future maintenance.
-
Test in non-production first – Create and remove links in a test folder before applying to critical paths.
-
Consider OneDrive and cloud sync – Some sync tools handle links differently; test behavior with your setup.
-
Use fsutil for hard link info –
fsutil hardlink list filenameshows all hard links to a file.
Troubleshooting Common Issues
"You do not have sufficient privilege to perform this operation"
Problem: Mklink fails when creating symbolic links.
Cause: Symbolic links require Administrator privileges. Standard users cannot create them.
Solution: Right-click Command Prompt, select "Run as administrator," and run the mklink command again. For directory-only links without admin, use mklink /J (junction) instead.
Prevention: Use junctions when Administrator access is not available, or ensure CMD is elevated before running mklink.
"Cannot create a file when that file already exists"
Problem: Mklink reports the link path already exists.
Cause: A file or folder already exists at the link path. Mklink cannot overwrite.
Solution: Remove or rename the existing item, or choose a different link path. Use dir to verify the path is clear.
Prevention: Check that the link path does not exist before running mklink.
"The system cannot find the file specified"
Problem: Mklink cannot find the target.
Cause: Target path is wrong, target does not exist, or path has typos. Hard links and junctions require existing targets.
Solution: Verify the target path with dir or cd. Use absolute paths for junctions. Ensure the target exists for hard links.
Prevention: Use Tab completion for paths and test with dir target_path before creating links.
"Access is denied" on network paths
Problem: Creating a symbolic link to a network path fails.
Cause: Network paths may require additional permissions or configuration. Some environments restrict symbolic links to network locations.
Solution: Ensure you have read/write access to the network path. Try mapping the network drive first with net use, then create the link to the mapped path. Verify Group Policy allows symbolic links.
Prevention: Test network link creation in a controlled environment before deployment.
Junction points to wrong directory
Problem: Junction does not show expected content.
Cause: Target path was incorrect when created, or target was moved.
Solution: Remove the junction with rmdir link_path and recreate with the correct target. Use dir /AL to list junctions and verify paths.
Prevention: Double-check target paths when creating junctions; use absolute paths.
Related Commands
subst – Virtual Drive Mapping
subst maps folders to drive letters (e.g., subst V: C:\Folder). Use subst for quick drive-letter access; use mklink when you need a folder or file to appear at a specific path. Subst is session-based; mklink links persist until explicitly removed.
robocopy – Copy with Mirroring
robocopy copies and syncs directories. Use robocopy when you need actual copies; use mklink when you want pointers without duplicating data. Combine both: robocopy for initial sync, mklink for path aliasing.
xcopy – File and Directory Copy
xcopy copies files and directories. Use xcopy when migrating or backing up; use mklink when the goal is a pointer rather than a copy.
fsutil – Hard Link Management
fsutil hardlink list lists all hard links to a file. Use after creating hard links with mklink /H to verify or audit link relationships.
takeown and icacls – Permissions
When links fail due to permissions, use takeown and icacls to adjust ownership and access. Required when linking to protected system directories.
Frequently Asked Questions
What is the difference between mklink /D and mklink /J?
mklink /D creates a directory symbolic link; mklink /J creates a directory junction. Symbolic links can use relative paths and point to non-existent targets but require Administrator. Junctions require absolute paths and existing targets but work without elevation. Use /J when you cannot run as Administrator.
Does mklink require Administrator?
Symbolic links (default and /D) require Administrator privileges. Hard links (/H) and directory junctions (/J) do not require Administrator. Run Command Prompt as Administrator for symbolic links.
How do I delete a symbolic link or junction?
Use rmdir link_path for directory symbolic links and junctions. Use del link_path for file symbolic links and hard links. This removes the link, not the target. The target files and folders remain unchanged.
Can mklink work across different drives?
Symbolic links can span drives. Hard links cannot—both link and target must be on the same volume. Directory junctions typically use absolute paths and can reference different drives.
What happens if I delete the target of a symbolic link?
If you delete the target, the symbolic link becomes a "broken" or "orphaned" link. Accessing it will fail. The link itself remains until you delete it. Hard links are different: deleting one hard link does not affect others until all links are removed.
How do I list all symbolic links in a directory?
Use dir /AL to list symbolic links and junctions in the current directory. The "L" attribute indicates a reparse point (link). Combine with /S to search recursively.
Can I create a symbolic link to a network path?
Yes, symbolic links can point to UNC paths (e.g., \\Server\Share\Folder). Administrator privileges are required. Some network or Group Policy settings may restrict this.
What is a hard link and when should I use it?
A hard link is an additional directory entry for the same file data. Use it when you need multiple names for one file on the same volume, such as for backups or deduplication. Hard links cannot point to directories.
Why does mklink say "cannot create a file when that file already exists"?
The link path you specified already exists as a file or folder. Mklink cannot overwrite. Delete or rename the existing item, or choose a different link path.
Can I use mklink in a batch script?
Yes. For symbolic links, the batch script must run as Administrator. For junctions and hard links, no elevation is needed. Use @echo off and error checking (if errorlevel 1) for robustness.
How do I create a symbolic link with a relative path?
Specify the target as a relative path: mklink link.txt ..\Folder\file.txt. The path is resolved relative to the link's location. Useful for portable scripts.
Is mklink available in PowerShell?
Mklink is a CMD command. In PowerShell, you can call it directly: cmd /c mklink /D C:\Link C:\Target. Alternatively, use New-Item -ItemType SymbolicLink for native PowerShell symbolic link creation.
Quick Reference Card
| Command | Purpose | Example |
|---|---|---|
mklink link.txt target.txt | Create file symbolic link | Point to file |
mklink /D C:\Link C:\Target | Create directory symbolic link | Folder alias |
mklink /H copy.txt original.txt | Create hard link | Same file, two names |
mklink /J C:\Junction C:\Target | Create directory junction | No admin needed |
rmdir link_path | Remove directory link | Delete junction/symlink dir |
del link_path | Remove file link | Delete file symlink/hard link |
dir /AL | List symbolic links | Find links in directory |
Try the Mklink Command in Our Simulator
Practice the mklink command safely in our Windows Command Simulator. Run mklink, mklink /D, and mklink /J examples in your browser without affecting your system.
Visit the Commands Reference for a full list of supported Windows CMD commands, including file system and disk management utilities.
Summary
The mklink command creates symbolic links, hard links, and directory junctions in Windows. Use /D for directory symbolic links, /H for hard links, and /J for junctions. Symbolic links require Administrator privileges; junctions and hard links do not.
Choose the right type: symbolic links for flexibility across drives, hard links for file deduplication on one volume, and junctions when you need directory links without elevation. Always verify paths before creation and use dir /AL to audit existing links. Master mklink for efficient file system organization, application compatibility, and development workflows.