[Deep Analysis] Hard Links, Symbolic Links, and Directory Links in Windows: Principles and Applications

[Deep Dive] Hard Links, Symbolic Links, and Directory Junctions in Windows: Principles and Applications

Today, I’ll walk you through three types of file links in Windows systems: Hard Links, Symbolic Links, and Directory Junctions. While they may appear similar, their underlying principles and use cases are quite different.

I’ll use a series of examples to help you better understand their differences, advantages, and limitations, enabling you to effectively leverage these tools in your daily work.


What is a Hard Link?

A hard link is essentially multiple identifiers for a file on disk, all pointing to the same data blocks. In other words, different hard links are just multiple names for the same file, pointing to the same file content (data blocks) and sharing the same file data.

How Hard Links Work

In Windows, each file has a unique “inode“ that contains the physical storage location of the file. A hard link is essentially a different path pointing to the same inode, and they share the same data blocks.

Use Cases for Hard Links

Hard links are suitable for scenarios where you need to reference the same file content multiple times. For example:

  • Backup and Data Redundancy: When you need to ensure a file is backed up in multiple locations, you can use hard links. No matter which hard link is deleted, the file content remains intact until all hard links are removed.
  • Space Saving: Since hard links reference the same data blocks, they don’t consume additional disk space. No matter how many hard links you create for a file, it only occupies one unit of disk space.

Advantages and Limitations of Hard Links

  • Advantages:

    • No additional space consumption.
    • Data sharing: deleting one hard link doesn’t affect the data; the file data is only deleted when all hard links are removed.
  • Limitations:

    • Cannot be used across file systems (i.e., cannot create hard links between different partitions).
    • Cannot create hard links for directories.
    • Only works with files, not folders.
    • You may forget how many hard links you’ve created, leading to undeleted files occupying disk space.

Example:
Suppose we have a file test.txt on the desktop. We can create a hard link pointing to test.txt at another path, C:\Users\Documents:

1
mklink /H C:\Users\%username%\Documents\test.txt C:\Users\%username%\Desktop\test.txt

At this point, C:\Users\%username%\Documents\test.txt and C:\Users\%username%\Desktop\test.txt point to the same data blocks on disk.


What is a Symbolic Link?

A symbolic link is a special type of file that contains a path pointing to another file or directory.

A symbolic link points to the path of the target file, not directly to the file’s data blocks.

Simply put, a symbolic link is like a shortcut.

How Symbolic Links Work

A symbolic link stores a text path pointing to another file or directory. The operating system reads this path to locate the target file. Therefore, if the target file is moved or modified, the symbolic link will still point to the original path, causing it to break.

Use Cases for Symbolic Links

  • Shortcuts and Redirection: In Windows, symbolic links are often used to create shortcuts. For example, many programs have long installation paths; you can use a symbolic link to map a long path to a shorter one for easier access.
  • Cross-Disk or Cross-Partition References: Symbolic links can be created across disks or partitions, solving the cross-disk limitation of hard links.

Advantages and Limitations of Symbolic Links

  • Advantages:
    • Can be created across disk partitions.
    • Supports links to both directories and files.
    • Deleting a symbolic link does not affect the target file’s content.
  • Limitations:
    • If the target file is deleted or moved, the symbolic link becomes invalid and inaccessible.

Example:
Suppose we have a folder C:\Data and want to create a symbolic link pointing to it at C:\Backup. You can use the following command:

1
mklink /D C:\Backup C:\Data

Now, when you access C:\Backup, you are actually accessing the contents of C:\Data.


Directory Junction

What is a Directory Junction?

A directory junction (also known as a soft link or junction) is a special type of link similar to a symbolic link. Unlike symbolic links, directory junctions only support links to directories, not files. A directory junction maps one directory to another location.

How Directory Junctions Work

A directory junction points to a directory and creates a new path in the file system. Unlike symbolic links, directory junctions directly redirect directory access within the operating system, functioning like a virtual folder.

Simply put, if we create a directory junction at C:\ pointing to a folder D:\Data, the operating system will believe that there is actually a folder named Data in the root of the C drive. When you open this Data folder from the C drive root, the address bar in File Explorer will show the path as C:\Data.

This allows us to trick both the operating system and software.

Use Cases for Directory Junctions

  • System Migration and Storage Management: You can migrate the contents of a directory to another location and create a directory junction at the original path, keeping programs running normally.
  • Multi-Location Data Storage: For example, if your system has multiple storage drives, you can use directory junctions to map a folder from one disk to another.

Advantages and Limitations of Directory Junctions

  • Advantages:
    • Only works with directories, avoiding path issues common with symbolic links.
    • Can be created across partitions.
  • Limitations:
    • Cannot be used for files.

Example:
Suppose you want to move C:\Users\OldData to another disk (e.g., D:\Data) while maintaining access to C:\Users\OldData. You can use a directory junction:

1
mklink /J C:\Users\OldData D:\Data

Now, accessing C:\Users\OldData actually accesses the contents of D:\Data.

So, what happens if we move a directory junction to another location?

The answer is that all files in the source folder of the directory junction will be moved to that target location.

Afterward, the moved directory junction becomes a regular folder.


Type Hard Link Symbolic Link Directory Junction
Link Target Files only Files or directories Directories only
Cross-Disk Support Not supported Supported Supported
Space Usage No extra space Minimal space Minimal space
Deletion Impact File deleted only when all hard links are removed Deleting symbolic link doesn’t affect target file Deleting directory junction doesn’t affect target directory
Permissions Available to regular users Requires administrator privileges Requires administrator privileges

By understanding the principles, applications, advantages, and limitations of hard links, symbolic links, and directory junctions, I hope you now have a clearer picture of how these file linking technologies work in Windows.

Using these links wisely in your daily work can not only boost efficiency but also help you better manage your files and directory structures.


[Deep Analysis] Hard Links, Symbolic Links, and Directory Links in Windows: Principles and Applications
https://en.lvlele.top/186-windows-hard-links-symbolic-links-1/
Author
Lvlele 吕了了
Posted on
June 4, 2026
Licensed under