大网数据广告活动
磁盘与文件系统

Hard Links and Junctions

· 52CE 我爱测

Provides an overview of hard links and junctions. Learn how to create and manage hard links and junctions in the NTFS file system.

The NTFS file system supports three types of file links: hard links, junctions, and symbolic links. This article is an overview of hard links and junctions. For information about symbolic links, see Create symbolic links.

Hard links

A hard link is the file-system representation of a file by which more than one path references a single file in the same volume. To create a hard link, use the CreateHardLinkA function.

Any changes made to a hard-linked file are instantly visible to applications that access it through the links that reference it. The attributes on the file are reflected in every hard link to that file, and changes to that file's attributes propagate to all the hard links. However, the directory entry size and attribute information of the file are visibly updated only at the link through which the change was made. For example, if you clear the read-only attribute flag on a particular hard link so you can delete that hard link, and there are multiple hard links to the file, the other hard links display that the read-only attribute is still set, which isn't true. To change the file back to the read-only state, you must set the read-only flag on the file from one of its remaining hard links.

For example, in a system where C: and D: are local drives and Z: is a network drive mapped to \\fred\share, the following references are permitted as a hard link:

  • C:\dira\ethel.txt linked to C:\dirb\dirc\lucy.txt
  • D:\dir1\tinker.txt linked to D:\dir2\dirx\bell.txt
  • C:\diry\bob.bak linked to C:\dir2\mina.txt

This is because all the links are files on the same volume. Hard links can't reference directories, only files, and they can't reference files on different volumes.

The following references aren't permitted:

  • C:\dira linked to C:\dirb
  • C:\dira\ethel.txt linked to D:\dirb\lucy.txt
  • C:\dira\ethel.txt linked to Z:\dirb\lucy.txt

To delete a hard link, use the DeleteFileA function. You can delete hard links in any order regardless of the order in which they're created.

Junctions

A junction (also called a soft link) differs from a hard link in that the storage objects it references are separate directories. A junction can also link directories located on different local volumes on the same computer. Otherwise, junctions operate identically to hard links. Junctions are implemented through reparse points.

Assuming the same conditions in the Hard Links section, the following references are permitted as junctions:

  • C:\dira linked to C:\dirb\dirc
  • C:\dirx linked to D:\diry

The following references aren't permitted because they reference mapped network volumes, or they directly reference files:

  • C:\dira\one.txt linked to C:\dirb\two.txt
  • C:\dir1 linked to Z:\dir2

Related content

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 07/08/2025
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。