Compare four different file (folder) links on Windows (NTFS hard links, junction points, symbolic links, and well-known shortcuts)

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:

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.

Using mklink command, you can create a “hard link”, “junction points” and “symbolic link”.

> 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:

mklink /J current %APPDATA%\walterlv\packages\1.0.0

That is to create a junction point linking to %APPDATA%\walterlv\packages\1.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:

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 ✔️ ✔️
Nees to run as Administrator Yes No No
Supports linking across volumes ✔️(Local Machine only) ✔️(including remote path such as SMB)
Introduced since Supports since Windows NT 3.1
API 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.

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:


References

本文会经常更新,请阅读原文: https://blog.walterlv.com/post/ntfs-link-comparisons-en.html ,以避免陈旧错误知识的误导,同时有更好的阅读体验。

如果你想持续阅读我的最新博客,请点击 RSS 订阅,或者前往 CSDN 关注我的主页

知识共享许可协议 本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。欢迎转载、使用、重新发布,但务必保留文章署名 吕毅 (包含链接: https://blog.walterlv.com ),不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。如有任何疑问,请 与我联系 ([email protected])