MKLink – Windows CMD Command
Create a symbolic link to a directory or a file, or create a hard file link or directory junction.
MKLINK [[/D] | [/H] | [/J]] LinkName Target
/D Create a Directory symbolic link. (default is file)
/H Create a hard link instead of a symbolic link.
/J Create a Directory Junction.
LinkName The new symbolic link name.
Target The path (relative or absolute) that the new link refers to.
Types of Link
|Can link to files?||Can link to folders?||Can link across hard drives?||Supported on:||Can point to a non-existent target?||Can be relative?||How to delete:|
|Hard link||Yes||No||No||Windows 3.5+||No||No||Del|
|No||Yes||Y (on the same computer)||Windows 2000+||Yes||No||RD|
|Symbolic link||Yes||Yes||Yes||Vista+||Yes||Yes (on the same volume)||RD folder or Del file|
Symbolic links are transparent to users; the links appear as normal NTFS files or directories and can be acted upon by the user or application in exactly the same manner. Symbolic links can span volumes and can use UNC paths.
A symlink can be an absolute path C:\Programs or a path relative to the link’s location \Programs.
Symbolic Links and Directory Junctions are implemented using reparse points.
Hard Links are implemented with multiple file table entries that point to the same inode – the same as Unix hard links. If the original filename is deleted, the hard link will still work – it points directly to the data on disk.
It is possible (but not advisable) to create two links that point to each other in a loop or a link that targets itself. Symbolic links can expose security vulnerabilities in applications that aren’t designed to handle them.
List existing Links and Junctions
The standard DIR command will display Symbolic Links, indicated with <SYMLINKD>
The DIR /A:S command will display Junctions, indicated with <JUNCTION>
DIR /A:S %userprofile%
By default, only Administrators can create symbolic links. The security setting ‘Create symbolic links’ can be granted at Configuration\Windows Settings\Security Settings\Local Policies\User Rights Assignment\
Creating a symbolic link requires elevation, but from Windows 10 build 14972, symlinks can be created without needing to elevate the console as administrator – this does however require that you have Developer Mode enabled.
If the link was successfully created %ERRORLEVEL% = 0
Link could not be created or bad parameters given %ERRORLEVEL% = 1