Since Windows Vista, Microsoft has included native support for symbolic links (symlinks) through the mklink
command. This powerful feature allows developers to create file system references that behave similarly to Unix symlinks.
Symbolic links are supported in these Windows editions:
- Windows Vista and later (all consumer editions)
- Windows Server 2008 and later
- Windows 10/11 (all versions)
To create a symbolic link, you'll need to run Command Prompt as Administrator:
mklink [[/d] | [/h] | [/j]] <link> <target>
File symlink example:
mklink C:\shortcut.txt C:\very\long\path\to\original.txt
Directory symlink example:
mklink /D C:\linked_dir C:\actual\project\directory
Switch | Type | Description |
---|---|---|
(none) | File symbolic link | Creates a symbolic link to a file |
/D | Directory symbolic link | Creates a symbolic link to a directory |
/H | Hard link | Creates a hard link to a file |
/J | Directory junction | Creates a directory junction |
For PowerShell users, you can create symlinks using:
New-Item -ItemType SymbolicLink -Path "C:\link" -Target "C:\target"
- Symbolic links require administrator privileges
- Consider path length limitations (260 chars by default)
- Network paths are supported as targets
- Symlinks can be relative using
mklink /D link ..\target
To verify if a file is a symlink:
dir /AL
This lists all symbolic links in the current directory.
Introduced in Windows Vista (NT 6.0), symbolic links (symlinks
) function similarly to their Unix counterparts, creating pointer references to files or directories. Unlike shortcuts (.lnk files), symlinks are handled at the filesystem level and are transparent to applications.
Supported Windows versions include:
- Client: Windows Vista+ (including Windows 10/11)
- Server: Windows Server 2008+
Required privileges: Administrator rights are mandatory when creating symlinks due to security implications (symbolic link attacks).
The mklink
command provides the primary interface:
:: Create file symlink
mklink NewFileLink.txt C:\Original\TargetFile.txt
:: Create directory symlink (/D flag)
mklink /D NewFolderLink C:\Original\TargetFolder
:: Create hard link (alternative for files)
mklink /H HardLink.txt Original.txt
For modern scripting environments:
# Requires PS 5.0+ (Win10+)
New-Item -ItemType SymbolicLink -Path "LinkName" -Target "TargetPath"
# Directory example
New-Item -ItemType SymbolicLink -Path "C:\Links\Docs" -Target "D:\RealDocuments" -Force
Using Windows API via P/Invoke:
[DllImport("kernel32.dll")]
static extern bool CreateSymbolicLink(
string lpSymlinkFileName,
string lpTargetFileName,
int dwFlags);
const int SYMBOLIC_LINK_FLAG_FILE = 0x0;
const int SYMBOLIC_LINK_FLAG_DIRECTORY = 0x1;
void CreateSymLink(string linkPath, string targetPath, bool isDirectory)
{
var flags = isDirectory ?
SYMBOLIC_LINK_FLAG_DIRECTORY :
SYMBOLIC_LINK_FLAG_FILE;
if (!CreateSymbolicLink(linkPath, targetPath, flags))
throw new Win32Exception();
}
- Development environments: Mapping node_modules across projects
- Server deployments: Redirecting log directories to larger drives
- Legacy app support: Creating compatibility paths for older software
If symlinks fail to work:
- Verify Group Policy settings (
Computer Configuration > Windows Settings > Security Settings > Local Policies > User Rights Assignment > Create symbolic links
) - Check filesystem type (NTFS required)
- Ensure developer mode is enabled on Windows 10/11