MKLINK – Create and Use Links in Windows

MKLINK – Create and Use Links in Windows

How to Create and Use Links with MKLINK in Windows

   Information
As so many other things in computing, Windows Links seem more complicated to understand and use than what they really are in reality.

This tutorial will tell you how to create and use links using MKLINK to redirect system queries made to a local or network storage location to another location.

In this tutorial we will concentrate on the most important link type, a Directory Junction. A junction is a very practical way to customize your file handling and procedures.


A Link is basically nothing more than a shortcut. Its purpose is to get Windows to think that a file or folder which is physically located in folder Real on drive A is in fact in folder Fake on drive B by creating a link between B:\Fake (a link or junction) and A:\Real (a target folder). Opening the link for instance in Explorer shows contents of target, saving a document to link actually saves it on target.

As Windows now gets a query from user to open B:\Fake this query is sent to A:\Real. In reality the location B:\Fake does not exist but system answers this query as it was a real folder instead of just a symbolic link and presents user the contents of A:\Real as if it was contents of B:\Fake. Sounds complicated? Don’t worry, it’s quite easy in fact.



Part 1: What is a Link?

   Note
A Link in Windows is a virtual object that points to a real physical location. It can be compared to Windows desktop shortcut, doing essentially the same thing in redirecting user to a physical storage location.


A Link can be so called Hard Link linking one file to a target file, or a Soft Link linking a folder to a target folder. Soft Links are also called Symbolic Links. Third link type is Junction, basically a hard link but as hard links can only link files we need to use junctions to link folders.

If you are using Windows Vista or later you have most probably used links without ever noticing it. In Windows XP all user data was saved in a folder called C:\Documents and Settings (default name and location). Windows Vista changed this; instead of Documents and Settings the data was divided between two system folders, C:\Users for user specific application data and personal files and folders, and C:\ProgramData for all users shared application data. To allow backwards compatibility all Windows versions since Vista have a link C:\Documents and Settings with two target folders, ProgramData and Users.

You can check this by yourself by allowing protected system files and folders to be shown and opening C: drive on Explorer:
mklink_01.png
(Please notice, screenshots from Windows 8 but links work the same way on Windows 7. Highlighted with yellow = visible system folders created by Windows installation, red = hidden or protected system folders.)

If you try to open Documents and Settings you get an "Access Denied" message. It does not exist, there is no such folder on your C: drive but it is needed for legacy software.

An example: You want to install Microsoft Office XP on your Windows 7. As Office XP was published for Windows XP long before Vista it uses the XP system folder Documents and Settings to store user data. Vista and later Windows do no longer have this folder so a link is needed. Office XP setup thinks it is creating files and folders normally in Documents and Settings but actually your Windows 7 is lying ;) to Office XP setup, not telling it those files and folders are in fact created in Users and ProgramData. Office XP setup does not notice this deception, installation works and later when user works with Office XP it still thinks the Documents and Settings folder is there, never learning the fact that all queries to that folder are sent further and returned as if they really came from Documents and Settings.



Part 2: Working with Directory Junctions

(1.) Command Syntax

Links are created wit command mklink, short from Make Link. Typing mklink /? on Command Prompt you get the command syntax and options:
Code:
[B]MKLINK [/B][[/D] | [/H] | [/J]] [B]Link [/B][B]Target[/B]
 
        [B]/D[/B]      Creates a directory symbolic link.  Default is a file symbolic link.
       [B]/H[/B]      Creates a hard link instead of a symbolic link.
        [B]/J [/B]  Creates a Directory Junction.
        [B]Link    [/B]specifies the new symbolic link name.
        [B]Target  [/B]specifies the path (relative or absolute) that the new link refers to.

(2.) Use an Elevated Command Prompt

You must use elevated command prompt to work with links.

(3.) Create a Link or a Junction

Creating a directory junction D:\Docs with target E:\Users\Kari\Documents:
Code:
mklink /j D:\Docs E:\Users\Kari\Documents
Windows tells you clearly if the creating of junction has succeeded:
mklink_02.png
(4.) Main principles when creating a link or a junction

  1. A file or a folder with the name of the intended Link name may not exist. The link file or folder name must be free to use, not reserved by an existing file or folder. If the name is reserved you get an error message. My D: drive already has a folder Test, this is what happens when trying to create a junction with D:\Test (already an existing folder) as link and E:\Users as target:
    mklink_03.png
    Notice that command prompt is telling about a file already existing instead of a folder. This is because the system sees links as shortcuts (files) and not as folders.
  2. Target folder may but must not exist. If it does not exist at the time when a link is created it must be created before you can use the link:
    mklink_04.png
  3. Target can be another Link. Above in (3.) we created a junction D:\Docs with target E:\Users\Kari\Documents. Following command would now create a link C:\Docs with target D:\Docs:
    Code:
    mklink /j C:\Docs D:\Docs
    In fact Windows sees no difference if the target is a real physical folder location or just another link. In this case all queries to C:\Docs would be sent to D:\Docs which would send them further to E:\Users\Kari\Documents. If a user now opens C:\Docs in Explorer, it shows the contents of E:\Users\Kari\Documents:
    mklink_05.png
    Noticed something interesting in screenshot above? The target folder is called Documents but Explorer shows it as My Documents. This is because those "My ..." folders in your user profile folder are actually not real folders. They are directory links: My Videos is simply a link with target Videos and so on.
(5.) Remove or rename a link

Links and junctions can be renamed and removed as any real folders. System automatically modifies registry and sets the target to be the same for a renamed link as it was on the original link.

This is because even not really existing, the system handles links as if they were real existing folders. This is what Explorer shows when asked for Properties for our example junction D:\Docs:
mklink_07.png
Only way to really see it is in fact a junction is to get directory listing in command prompt:
mklink_06.png
The listing not only shows it is a junction but also its target folder.


Part 3: Practical Examples

A typical situation: You have bought a game that must be installed on root level folder C:\Games. Your C: drive is becoming full, so you decide to move the whole C:\Games folder to D:, delete now empty C:\Games (remember, link folder may not exist) and create a junction:
Code:
mklink /j C:\Games D:\Games
When launching the game it still assumes it is located on C: although you, me and Windows know better ;): it's "secretly" residing on D: but still using the old address on C:.

Another situation: You want to work with some pics from last Christmas, to edit them to be ready to be published on that website of yours. Pics are currently located in X:\Backups\Pictures\My Pictures\Holidays\Christmas 2012.

You can create a junction X:\Pics, and now whenever you want to work with those pics you just type X:\Pics to Run dialog to open the correct folder:
Code:
mklink /j X:\Pics "X:\Backups\Pictures\My Pictures\Holidays\Christmas 2012"
Notice that if a path contains spaces it must be set in between quotation marks as in above target path.

That's about it. Any feedback welcome.

Kari
 
Last edited:
Hello Pazzer, and welcome to Seven Forums.

Symbolic links are transparent to users; the links appear as normal files or directories.

Symbolic Links (Windows)

If you don't use the /d switch, it'll be a file symbolic link.

If you use the /d switch, it'll be a directory symbolic link.

Hope this helps, :)
Shawn
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Self built custom
OS
64-bit Windows 11 Pro for Workstations
CPU
Intel i7-8700K OC'd to 5 GHz
Motherboard
ASUS ROG Maximus XI Formula Z390
Memory
64 GB (4x16GB) G.SKILL TridentZ RGB DDR4 3600 MHz
Graphics Card(s)
ASUS ROG-STRIX-GTX1080TI-O11G-GAMING
Sound Card
Integrated
Monitor(s) Displays
2 x Samsung Odyssey G7 27"
Screen Resolution
2560x1440
Hard Drives
1TB Samsung 990 PRO M.2,
4TB Samsung 990 PRO PRO M.2,
TerraMaster F8 SSD Plus NAS
PSU
Seasonic Prime Titanium 850W
Case
Thermaltake Core P3
Cooling
Corsair Hydro H115i
Keyboard
Logitech wireless K800
Mouse
Logitech MX Master 4
Internet Speed
2 Gb/s Download and 100 Mb/s Upload
Antivirus
Malwarebyte Anti-Malware Premium
Browser
Google Chrome
Other Info
Logitech Z625 speaker system,
Logitech BRIO 4K Pro webcam,
HP Color LaserJet Pro MFP M477fdn,
APC SMART-UPS RT 1000 XL - SURT1000XLI,
Galaxy S23 Plus phone
Thanks for the quick response Shawn. Sorry to be thick, but does that mean :-
a:\filename1 points to b:\filename2 in the default case and
a:\directory1 (and all subs & files) point to b:\directory2 in the mklink /D case?
 

My Computer

Computer type
Tablet
Computer Manufacturer/Model Number
Samsung Series 7 Slate XE700T1A
OS
Windows 8.1 Ult x64 & Windows 7 x32
Sorry, yes it's to create either a file (default) or folder (/d switch) symbolic link.
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Self built custom
OS
64-bit Windows 11 Pro for Workstations
CPU
Intel i7-8700K OC'd to 5 GHz
Motherboard
ASUS ROG Maximus XI Formula Z390
Memory
64 GB (4x16GB) G.SKILL TridentZ RGB DDR4 3600 MHz
Graphics Card(s)
ASUS ROG-STRIX-GTX1080TI-O11G-GAMING
Sound Card
Integrated
Monitor(s) Displays
2 x Samsung Odyssey G7 27"
Screen Resolution
2560x1440
Hard Drives
1TB Samsung 990 PRO M.2,
4TB Samsung 990 PRO PRO M.2,
TerraMaster F8 SSD Plus NAS
PSU
Seasonic Prime Titanium 850W
Case
Thermaltake Core P3
Cooling
Corsair Hydro H115i
Keyboard
Logitech wireless K800
Mouse
Logitech MX Master 4
Internet Speed
2 Gb/s Download and 100 Mb/s Upload
Antivirus
Malwarebyte Anti-Malware Premium
Browser
Google Chrome
Other Info
Logitech Z625 speaker system,
Logitech BRIO 4K Pro webcam,
HP Color LaserJet Pro MFP M477fdn,
APC SMART-UPS RT 1000 XL - SURT1000XLI,
Galaxy S23 Plus phone
Brilliant. I've now got Dropbox onto a microSD and released 50GB on my c:\ Thanks for all your help.
 

My Computer

Computer type
Tablet
Computer Manufacturer/Model Number
Samsung Series 7 Slate XE700T1A
OS
Windows 8.1 Ult x64 & Windows 7 x32
You're welcome. :)
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Self built custom
OS
64-bit Windows 11 Pro for Workstations
CPU
Intel i7-8700K OC'd to 5 GHz
Motherboard
ASUS ROG Maximus XI Formula Z390
Memory
64 GB (4x16GB) G.SKILL TridentZ RGB DDR4 3600 MHz
Graphics Card(s)
ASUS ROG-STRIX-GTX1080TI-O11G-GAMING
Sound Card
Integrated
Monitor(s) Displays
2 x Samsung Odyssey G7 27"
Screen Resolution
2560x1440
Hard Drives
1TB Samsung 990 PRO M.2,
4TB Samsung 990 PRO PRO M.2,
TerraMaster F8 SSD Plus NAS
PSU
Seasonic Prime Titanium 850W
Case
Thermaltake Core P3
Cooling
Corsair Hydro H115i
Keyboard
Logitech wireless K800
Mouse
Logitech MX Master 4
Internet Speed
2 Gb/s Download and 100 Mb/s Upload
Antivirus
Malwarebyte Anti-Malware Premium
Browser
Google Chrome
Other Info
Logitech Z625 speaker system,
Logitech BRIO 4K Pro webcam,
HP Color LaserJet Pro MFP M477fdn,
APC SMART-UPS RT 1000 XL - SURT1000XLI,
Galaxy S23 Plus phone
Hi - I'm also wanting to move the Dropbox folder from default location at C:\Users\username\Dropbox to D:\Dropbox which the data partition on the same internal SSD and create a directory link to it...could someone list all the steps I need to do in detail? Thank you!
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Dell XPS 13 (L321X) x64
OS
Windows 7 Pro Version 6.1.7601 Service Pack 1 Build 7601, clean OEM re-install
CPU
Intel core i5-2467M CPU @160GHz
Motherboard
Dell Inc. 085X6F A00
Memory
4Gb installed RAM
Graphics Card(s)
Intel HD Graphics 3000
Hard Drives
SAMSUNG SSD PM830 mSATA 128GB ATA Device, ACHI enabled
SEAGATE FREEAGENT USB HDD - 640GB
Antivirus
Kaspersky Internet Security 2014 G patch
Browser
Firefox 29.1

My Computer

Computer type
Tablet
Computer Manufacturer/Model Number
Samsung Series 7 Slate XE700T1A
OS
Windows 8.1 Ult x64 & Windows 7 x32
Moving Dropbox

Hi - I'm also wanting to move the Dropbox folder from default location at C:\Users\username\Dropbox to D:\Dropbox which the data partition on the same internal SSD and create a directory link to it...could someone list all the steps I need to do in detail? Thank you!

dpwoodpecker - sounds like you don't need symbolic linking just to move Dropbox to another partition on your primary drive. (i.e. not, say, to a MicroSD)
In your local Dropbox - Simply click Dropbox icon in System Tray, Tools symbol (top right), from dropdown menu choose 'Preferences', Account, Location, Move, then put in your D:\ location.
 

My Computer

Computer type
Tablet
Computer Manufacturer/Model Number
Samsung Series 7 Slate XE700T1A
OS
Windows 8.1 Ult x64 & Windows 7 x32
Thanks for the clear instructions!
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Dell XPS 13 (L321X) x64
OS
Windows 7 Pro Version 6.1.7601 Service Pack 1 Build 7601, clean OEM re-install
CPU
Intel core i5-2467M CPU @160GHz
Motherboard
Dell Inc. 085X6F A00
Memory
4Gb installed RAM
Graphics Card(s)
Intel HD Graphics 3000
Hard Drives
SAMSUNG SSD PM830 mSATA 128GB ATA Device, ACHI enabled
SEAGATE FREEAGENT USB HDD - 640GB
Antivirus
Kaspersky Internet Security 2014 G patch
Browser
Firefox 29.1
I created mklink and it returned me link created. However when I tried to access by clicking the folder that I created, it gave me error "The filename, directory name, or volume label syntax is incorrect". Is anyone facing this issue before?
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Dell
OS
Windows 7 Enterprise 64bit
I'm using makelink with a Classic Shell toolbar. I'd like to make it so that when I click an item it makes a link to it, but if there's nothing selected, have it make a link to the current folder. I was told I'd need a .bat file with the if argument. What exact commands would I use to make the file?
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Lenovo Thinkpad E540
OS
Windows 7 Ultimate x64
CPU
i7-4702M
Antivirus
Norton 360
Browser
Pale Moon
Last edited:

My Computer

Computer type
PC/Desktop
OS
Windows 7 Ultimate x64
CPU
Intel Core 2 Duo E7200 @ 2.53GHz
Motherboard
BIOSTAR Group G31-M7 TE
Memory
4,00GB Dual-Channel DDR2 @ 398MHz (5-5-5-18)
Graphics Card(s)
512MB NVIDIA GeForce 8500 GT (Gigabyte)
Sound Card
Realtek High Definition Audio 5.1
Screen Resolution
1280x1024 pixels
Hard Drives
WDC WD1002FAEX-00Z3A0 ATA Device 931 GB
Browser
Comodo Dragon
Other Info
Optical Drives: HL-DT-ST DVDRAM GSA-4167B ATA Device;
Speccy: http://speccy.piriform.com/results/mpAug3INnJkpJFsddkm8sms
Hi Kari et al,

Thanks for starting a thread and hosting great contributions! Alas, I still need help getting across the goal line with network drives.

Using examples here and on MS's site, I created a test symbolic folder link called "Lighting" here:
"F:\junk\TESTING Standard Project Folder TESTING\Documents\17-Specifications"
It points to the "Lighting" folder here:
"N:\junk\TESTING Standard Project Folder TESTING\Drawings\04-Design Development\01 Finishes Lighting & Specifications\Lighting"
The link has these issues:

  • Right-clicking, selecting Properties and Open Folder Location leads to the Lighting folder (without opening it).
  • Double-clicking on the link in Windows doesn't throw an error, but does produce an "Open With" window with (irrelevant) choices.
  • Efforts to copy the link fail, claiming that "The filename, directory name, or volume label syntax is incorrect."
I really appreciate hearing of Skol's success. Does anyone have any ideas about what I'm doing wrong?

Thanks for all comments!
 

My Computer

OS
XP/32, 7/64
Please post the mklink command exactly as you have given it (full paths, dots, colons, spaces and all characters as you have used them in the command, using the exactly same syntax you have used).

An example mklink command:

mklink /j D:\Docs E:\Users\Kari\Documents

I want you to post your command as above, the complete command line.
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
HP ENVY 17-1150eg
OS
Windows 10 Pro x64 EN-GB
CPU
1.6 GHz Intel Core i7-720QM Processor
Memory
6 GB
Graphics Card(s)
ATI Mobility Radeon HD 5850 Graphics
Sound Card
Beats sound system with integrated subwoofer
Monitor(s) Displays
17" laptop display, 22" LED and 32" Full HD TV through HDMI
Screen Resolution
1600*900 (1), 1920*1080 (2&3)
Hard Drives
Internal: 2 x 500 GB SATA Hard Disk Drive 7200 rpm
External: 2TB for backups, 3TB USB3 network drive for media
Cooling
As Envy runs a bit warm, I have it on a Cooler Master pad
Keyboard
Logitech diNovo Media Desktop Laser (bluetooth)
Mouse
Logitech Performance Mouse MX
Internet Speed
50/10 Mbps VDSL
Antivirus
Windows Defender 4.3.9431.0
Browser
Maxthon 3.5.2., IE11
Thanks! It was created within admin-enabled command prompt while within the following directory:

"F:\junk\TESTING Standard Project Folder TESTING\Documents\17-Specifications"

mklink /d "Lighting" "N:\junk\TESTING Standard Project Folder TESTING\Drawings\04-Design Development\01 Finishes Lighting & Specifications\Lighting"

FYIs: F and N are the same location. The Properties browse confirms that Windows properly identifies it. I can't copy it in a window or in command prompt.
 

My Computer

OS
XP/32, 7/64
One more question, is TESTING Standard Project Folder TESTING really name of a folder in your target's path? Also, the link must contain full path for example C:\Lighting or X:\Docs\Lighting. Your's only have "Lighting" without path.
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
HP ENVY 17-1150eg
OS
Windows 10 Pro x64 EN-GB
CPU
1.6 GHz Intel Core i7-720QM Processor
Memory
6 GB
Graphics Card(s)
ATI Mobility Radeon HD 5850 Graphics
Sound Card
Beats sound system with integrated subwoofer
Monitor(s) Displays
17" laptop display, 22" LED and 32" Full HD TV through HDMI
Screen Resolution
1600*900 (1), 1920*1080 (2&3)
Hard Drives
Internal: 2 x 500 GB SATA Hard Disk Drive 7200 rpm
External: 2TB for backups, 3TB USB3 network drive for media
Cooling
As Envy runs a bit warm, I have it on a Cooler Master pad
Keyboard
Logitech diNovo Media Desktop Laser (bluetooth)
Mouse
Logitech Performance Mouse MX
Internet Speed
50/10 Mbps VDSL
Antivirus
Windows Defender 4.3.9431.0
Browser
Maxthon 3.5.2., IE11
Oops; thanks, that makes the shortcut work as expected in the original location. Now, the shortcut/link works as expected there, and running the DIR command there describes the entity as a <SYMLINKD>.

The final hurdle is making the relative reference work on the live volume. This means copying it (or, in live use, the folder set in which it lives) to the production drive.

Here is where it appears to fail: When copied to the target location, the link becomes a directory there. In fact, it becomes a directory even when copied into a different folder in its own folder set.

I had thought that the symbolic reference would enable me to create a portable link whose reference would always be relative to the specification regardless of location as long as the relevant folder structure remained intact.

Might I be trying to use the entity in a way that is different from its intended use, or might it not work on Windows 2008 virtual servers running over xenserver?
 

My Computer

OS
XP/32, 7/64
The links and targets cannot be portable. Both link and target need an absolute path.
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
HP ENVY 17-1150eg
OS
Windows 10 Pro x64 EN-GB
CPU
1.6 GHz Intel Core i7-720QM Processor
Memory
6 GB
Graphics Card(s)
ATI Mobility Radeon HD 5850 Graphics
Sound Card
Beats sound system with integrated subwoofer
Monitor(s) Displays
17" laptop display, 22" LED and 32" Full HD TV through HDMI
Screen Resolution
1600*900 (1), 1920*1080 (2&3)
Hard Drives
Internal: 2 x 500 GB SATA Hard Disk Drive 7200 rpm
External: 2TB for backups, 3TB USB3 network drive for media
Cooling
As Envy runs a bit warm, I have it on a Cooler Master pad
Keyboard
Logitech diNovo Media Desktop Laser (bluetooth)
Mouse
Logitech Performance Mouse MX
Internet Speed
50/10 Mbps VDSL
Antivirus
Windows Defender 4.3.9431.0
Browser
Maxthon 3.5.2., IE11
Then I'm trying to use the symbolic link for something it's not intended to do. I'm looking for a way to build portable shortcuts (with relative references to their targets) into a template of folders so that, when users physically copy the template to a live destination, the copied shortcuts would point to the new destinations.

Autodesk uses "xrefs" - external references - in this way, with either absolute or relative references to files that support a main file being edited. Using relative references enables the entire file set to be moved to other drives or systems while preserving the external references.

Thanks for helping to clarify mklink and symbolic linking for me. I'll keep searching for my answer!
 

My Computer

OS
XP/32, 7/64
I have a post-it notes type app on my system where I keep all sorts of computer related info, including one titled "Junction Point Creation" which I'll replicate here. This is how I had to word it to myself for it to be completely clear. Since a certain measure of uncertainty usually accompanies this issue for many, hopefully it'll help clear any confusion, Kari's excellent article notwithstanding. Then again it may make things worse :shock: :confused::D :


Step 1.
 Move the folder in question from its current location ( OLDLOC ) to the new location where you'd like it to reside from now on ( NEWLOC )

Step 2.
 Execute : mklink /j "OLDLOC" "NEWLOC"

Step 3. ( optional )
 Set the 'h' ( hide ) attribute to the folder in question in OLDLOC ( not NEWLOC—the preceding command will have made it "reappear" in OLDLOC, i.e. in its original location… hence, the 'h' attribute if desired )
 

My Computer

OS
Windows® 7 (64-bit)
CPU
intel® Core™ i5-4690 @ 3.50 GHz
Motherboard
GIGABYTE™ H97-D3H
Memory
8 GB DDR3
Back
Top