![cover image](https://wikiwandv2-19431.kxcdn.com/_next/image?url=https://upload.wikimedia.org/wikipedia/commons/thumb/3/32/Hard_Link_Illustration.svg/langzh-tw-640px-Hard_Link_Illustration.svg.png&w=640&q=50)
硬連結
維基百科,自由的 encyclopedia
硬連結(英語:hard link)是電腦檔案系統中的多個檔案平等地共享同一個檔案儲存單元(如MFT條目、inode)。硬連結必須在同一個檔案系統中;一般使用者權限下的硬連結只能用於檔案,不能用於目錄,因為其父目錄就有歧義了。刪除一個檔案名字後,還可以用其它名字繼續訪問該檔案。硬連結只能用於同一個檔案系統(對於NTFS是限制於同一個分割區)。不能用於不存在的檔案。[1]
![](http://upload.wikimedia.org/wikipedia/commons/thumb/3/32/Hard_Link_Illustration.svg/220px-Hard_Link_Illustration.svg.png)
POSIX相容的作業系統,檔案或目錄的硬連結的參照計數可以用stat()(英語:stat (system call))或fstat()系統呼叫返回的struct stat
中的st_nlink
欄位。
NTFS的硬連結
Windows NT 3.1及後續版本支援NTFS硬連結。[2] Windows 2000引入了CreateHardLink()
函式以建立硬連結,但僅能用於檔案,不能用於目錄。[3]DeleteFile()
函式可刪除硬連結。
Windows終端使用者建立硬連結的方法:
fsutil
工具(Windows 2000引入)[4]mklink
,命令提示字元的內部命令 (Windows Vista和Windows Server 2008引入)[5]New-Item
,PowerShell命令[6]
終端使用者檢視檔案的硬連結的方法:
WinSxS使用硬連結跟蹤硬碟上部件的不同版本。
類Unix系統的硬連結
使用者建立硬連結的方法:
- ln
- link(英語:Link (Unix))
New-Item
,PowerShell的命令[6]
終端使用者檢視檔案的硬連結:
參見
- 符號連結:
- NTFS符號連結: NTFS支援四種類型的連結—硬連結、符號連結、連接點連結、卷安裝點
- 檔案捷徑:
- Mac作業系統別名(英語:alias (Mac OS))
- OS/2作業系統Shadow(英語:shadow (OS/2))
- freedup(英語:freedup) –
freedup
命令可以釋放磁碟空間,通過把冗餘的檔案用硬連結替代。
參考文獻
- Pitcher, Lew. Q & A: The difference between hard and soft links. [2021-11-26]. (原始內容存檔於2020-11-12).
- How hard links work. Microsoft Docs. [2021-11-26]. (原始內容存檔於2021-12-05).
- 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.
- Fsutil hardlink. Windows App Development. Microsoft. 18 April 2012 [2021-11-26]. (原始內容存檔於2021-11-26) –透過Microsoft Docs.
- 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
- FileSystemProvider.cs. PowerShell / PowerShell repo. Microsoft. Lines 8139–8234. 20 November 2021 [2021-11-26]. (原始內容存檔於2021-11-23) –透過GitHub.