硬鏈接

本頁使用了標題或全文手工轉換
維基百科,自由的百科全書

硬鏈接(英語: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.