Windows users often need to reference the same file or directory from multiple locations without duplicating the actual data. This is especially useful for managing game installation folders, redirecting application data to another drive, or keeping specific files synchronised across cloud storage services like OneDrive or Google Drive.
While standard shortcuts (.lnk files) allow you to quickly open a file, they are not recognised as real files by applications or the command line. To create a true reference that the operating system treats as the original file or folder, you need to use symbolic links.
What is a Symbolic Link?
A symbolic link (often called a symlink or soft link) is a file-system-level pointer. When an application attempts to read or write to a symbolic link, Windows automatically redirects that request to the target file or directory.
Unlike a standard Windows shortcut, a symbolic link operates seamlessly at the file system level. If you create a symbolic link to a folder, applications will read it exactly as if the original folder were located at the link’s path. This allows you to trick applications into reading data from a secondary hard drive while the application believes the data is still on the primary drive.
How to Use the mklink Command in Windows
In Windows, symbolic links are created using the Command Prompt. The utility used for this is mklink. Because creating symbolic links modifies the file system structure, you must run the Command Prompt as an Administrator.
- Open the Start menu.
- Search for cmd or Command Prompt.
- Right-click the result and select Run as administrator.
The standard syntax for the mklink command is:
mklink [[/d] | [/h] | [/j]] <link> <target>
- <link>: The path and name of the new symbolic link you want to create.
- <target>: The path to the existing file or folder that the link will point to.
1. How to Create a File Symbolic Link
By default, if you run mklink without any additional flags, it creates a symbolic link pointing to a file.
mklink "C:\Path\To\Link.txt" "D:\Path\To\OriginalTarget.txt"
In this example, opening Link.txt on the C: drive will seamlessly open and modify the contents of OriginalTarget.txt located on the D: drive.
2. How to Create a Directory Symbolic Link (/D)
If you need to link an entire folder rather than a single file, you must use the /D switch. This creates a directory symbolic link.
mklink /D "C:\Path\To\LinkFolder" "D:\Path\To\OriginalFolder"
This is extremely useful when an application requires data to be stored on the primary C: drive, but you are running out of space and want to store the actual data on a larger secondary drive. You move the original folder to the secondary drive and create a directory symbolic link in its original location.
3. How to Create a Directory Junction (/J)
A Directory Junction (created with the /J switch) is similar to a directory symbolic link but has slightly different underlying mechanics. The most significant difference for regular users is that creating a Directory Junction does not require Administrator privileges.
mklink /J "C:\Path\To\JunctionFolder" "D:\Path\To\OriginalFolder"
Junction points are strictly for local folders. You cannot create a junction point pointing to a network share, whereas a directory symbolic link (/D) can point to network locations.
4. How to Create a Hard Link (/H)
A Hard Link (created with the /H switch) makes a file appear as though it physically exists in multiple locations on the same drive. Unlike symbolic links, hard links point directly to the data on the disk, rather than pointing to the original file’s path.
mklink /H "C:\Path\To\HardLink.txt" "C:\Path\To\OriginalFile.txt"
Hard links can only be created for files, not directories, and both the link and the target must reside on the exact same hard drive partition.
How to Delete a Symbolic Link
Deleting a symbolic link is entirely safe. Because the link is merely a pointer, deleting the link does not delete the original target file or folder.
To delete a symbolic link, you can simply delete it through Windows File Explorer just as you would delete a normal file or folder. Alternatively, you can remove it using the Command Prompt:
- To delete a file symbolic link:
del "C:\Path\To\Link.txt" - To delete a directory symbolic link:
rmdir "C:\Path\To\LinkFolder"