It is well-known that mklink
is a command to create a variety of links on NTFS disk. But if you don’t know much about it or even never hear of it, it doesn’t matter because you know shortcuts at least. This post help you to lean more about mklink
and know the differences among the difference command options.
This post is written in multiple languages. Please select yours:
中文 English
Different ways of linking
Windows Vista announced the NTFS symbolic links, Windows 2000 began to have NTFS Reparse Point, and earlier Windows 95 introduced the shortcut. Backing to Windows 3.5 There are hard links. All of them provide you the power to access a same folder or file in difference paths.
mklink
Using mklink
command, you can create a “hard link”, “junction points” and “symbolic link”.
1 2 3 4 5 6 7 8 9 10 11 | > mklink Creates a symbolic link. MKLINK [[/D] | [/H] | [/J]] Link Target /D Creates a directory symbolic link. Default is a file symbolic link. /H Creates a hard link instead of a symbolic link. /J Creates a Directory Junction. Link Specifies the new symbolic link name. Target Specifies the path (rel |
---|
e.g:
1 | mklink /J current %APPDATA%walterlvpackages1.0.0 |
---|
That is to create a junction point linking to %APPDATA%walterlvpackages1.0.0
.
Shortcuts
Shortcuts is a Windows feature which is different to those introduced by the NTFS.
Shortcut is a file with a lnk
file extension. This file contains the info indicates how to open the linking file or directory. Maybe most applications use this lnk
file to execute their programs.
Others
Reparse Point has been in the Windows operating system since NTFS v3.0 (introduced with Windows 2000). In addition to our previously mentioned three types of reparse points made by mklink
, there are other types:
- Volume Mount Ppoints
- Distributed Link Tracking(DLT)
- Data Deduplication
- Hierarchical Storage Management(HSM)
- Native Structured Storage(NSS)
- Unix Doman Socket(socket)
- System Compression
- OneDrive
Comparison
Reading those words above, you may know the usage of mklink
but don’t know the difference between them. Then I’ve post them below:
Hard Link | Junction Point | Symbolic Link | |
---|---|---|---|
Command | mklink /H Link Target | mklink /J Link Target | mklink /D Link Target |
Description | Create an alias for a file so that different paths correspond to the data of the same file. | ||
Linking to files | ✔️ | ❌ | ❌ |
Linking to directories | ❌ | ✔️ | ✔️ |
Needs to run as Administrator | Yes | No | Mostly Yes [Tip1] |
Supports linking across volumes | ❌ | ✔️(Local Machine only) | ✔️(including remote path such as SMB) |
Introduced since | Supports since Windows NT 3.1API supports since Windows 2000 by CreateHardLink()Supports since Windows NT 6.0 by command mklink /H | Windows 2000 | Windows Vista |
Supports targets which is not exist | ❌ | ✔️ | ✔️ |
Link to relative directory | ❌ | ❌(You can create one with relative path but it will change to absolute path automatically.) | ✔️ |
How to remove | del | rd | rd / del |
When the reparse point is removed | Only after all hard links to the original file and the original file have been deleted will the file data be deleted. | The original folder is not affected after Windows Vista but is will be deleted in Windows 2000 / XP / 2003. | The original file/folder is not affected. |
When the original file/folder is removed | The hard link can still access the data of the file normally. | Directory connection failed, pointing to a directory that does not exist. | The symbolic link is invalid and points to a directory that does not exist. |
[Tip1]
: A post of Microsoft says, Starting with Windows 10 Insiders build 14972, symlinks can be created without needing to elevate the console as administrator. This will allow developers, tools and projects, that previously struggled to work effectively on Windows due to symlink issues, to behave just as efficiently and reliably as they do on Linux or OSX. (Below picture shows how to open the developer’s mode.)
Extras
If you create shortcuts in your start menu, and the shortcuts are linking to files that are in junction points. All the shortcuts will disappear after a Windows 10 updates. I’m reporting this bug to Microsoft, but before Microsoft resolve this bug we have to work around to avoid this bug. See the bug in scoop below:
- After the windows 10 updates, all shortcuts of scoop will disappear. · Issue #3941 · lukesampson/scoop
References
- NTFS reparse point - Wikipedia
- windows - What is the difference between NTFS Junction Points and Symbolic Links? - Stack Overflow
- Hard link - Wikipedia
- Create symbolic links (Windows 10) - Windows security - Microsoft Docs
- Symlinks in Windows 10! - Windows Developer Blog
本文会经常更新,请阅读原文: https://blog.walterlv.com/post/ntfs-link-comparisons-en.html ,以避免陈旧错误知识的误导,同时有更好的阅读体验。
本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。欢迎转载、使用、重新发布,但务必保留文章署名 吕毅 (包含链接: https://blog.walterlv.com ),不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。如有任何疑问,请 与我联系 ([email protected]) 。