硬链接(英語:hard link)是计算机文件系统中的多个文件平等地共享同一个文件存储单元(如MFT条目inode)。硬链接必须在同一个文件系统中;一般用户权限下的硬链接只能用于文件,不能用于目录,因为其父目录就有歧义了。删除一个文件名字后,还可以用其它名字继续访问该文件。硬链接只能用于同一个文件系统(对于NTFS是限制于同一个分区)。不能用于不存在的文件。[1]

硬链接概念图示

POSIX兼容的操作系统,文件或目录的硬链接的引用计数可以用stat()英语stat (system call)或fstat()系统调用返回的struct stat中的st_nlink字段。

NTFS的硬链接 编辑

Windows NT 3.1及后续版本支持NTFS硬链接。[2] Windows 2000引入了CreateHardLink()函数以创建硬链接,但仅能用于文件,不能用于目录。[3]DeleteFile()函数可删除硬链接。

Windows终端用户创建硬链接的方法:

终端用户查看文件的硬链接的方法:

  • fsutil 工具[4]
  • Get-ItemGet-ChildItem,PowerShell命令[7]

WinSxS使用硬链接跟踪硬盘上部件的不同版本。

类Unix系统的硬链接 编辑

用户创建硬链接的方法:

终端用户查看文件的硬链接:

  • stat方法
  • ls -l方法
  • Get-ItemGet-ChildItem,PowerShell命令[7]

参见 编辑

参考文献 编辑

  1. ^ Pitcher, Lew. Q & A: The difference between hard and soft links. [2021-11-26]. (原始内容存档于2020-11-12). 
  2. ^ How hard links work. Microsoft Docs. [2021-11-26]. (原始内容存档于2021-12-05). 
  3. ^ CreateHardLink Function. Windows Development. Microsoft. 10 March 2011. 原始内容存档于2 July 2011 –通过MSDN. Establishes a hard link between an existing file and a new file. This function is only supported on the NTFS file system, and only for files, not directories. 
  4. ^ 4.0 4.1 Fsutil hardlink. Windows App Development. Microsoft. 18 April 2012 [2021-11-26]. (原始内容存档于2021-11-26) –通过Microsoft Docs. 
  5. ^ Mklink. Microsoft Docs. Microsoft. 18 April 2012 [2021-11-26]. (原始内容存档于2021-11-26). 
  6. ^ 6.0 6.1 New-Item (PowerShell 3.0). Microsoft Docs. Microsoft. 22 June 2020 [2021-11-26]. (原始内容存档于2021-11-26). If your location is in a FileSystem drive, the following values are allowed: If your location is in a FileSystem drive, the following values are allowed: File[,] Directory[,] Junction[,] HardLink 
  7. ^ 7.0 7.1 FileSystemProvider.cs. PowerShell / PowerShell repo. Microsoft. Lines 8139–8234. 20 November 2021 [2021-11-26]. (原始内容存档于2021-11-23) –通过GitHub.