硬連結

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

硬連結(英語: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.