--------------------------------------------------------------------------
1)shortcut/快捷方式
以.lnk文件方式存在,適用於Explorer等應用程序。
非NTFS內置機制,從Win95開始得到支持。FAT32支持。
同時適用於文件、目錄。
只能使用絕對路徑。
可以跨盤符,可以跨主機,可以使用UNC路徑、網絡驅動器。
刪除shortcut,不影響target。
--------------------------------------------------------------------------
2)(file)hard link
假設本文讀者具有*nix基礎,此處不做hardlink的語義解釋。
NTFS內置機制,從Windows NT4開始得到支持。FAT32不支持。
只適用於文件。
只能使用絕對路徑。
hard link與targetfile必須位於同一volume,可以簡單理解成不能跨盤符。
在Explorer中刪除hard link,不影響targetfile。
刪除target file,不影響hardlink。事實上由於hard link的語義,此時剩下的
hardlink就是原始數據的唯一訪問點。
相關Win32API:
CreateHardLink()
CreateHardLinkTransacted()
創建:
mklink /H"hard link name" "target file"
fsutil.exehardlink create"hard link name" "target file"
查看:
fsutil.exehardlink list"hard link name"
fsutil.exehardlink list"target file"
二者效果一樣,hard link的語義本就如此。
--------------------------------------------------------------------------
3)(directory)junction point/softlink/reparsepoint
junction point也叫softlink,這是微軟官方文檔裏說的:
Hard Links andJunctions
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365006
junctionpoint的底層機制是NTFS的reparsepoint:
ReparsePoints
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365503
Junction v1.06
http://www.sysinternals.com
http://technet.microsoft.com/en-us/sysinternals/default.aspx
https://technet.microsoft.com/en-us/sysinternals/bb896768
Howto createand manipulateNTFS junction points
https://support.microsoft.com/en-us/kb/205524
NTFS內置機制,從Windows2000/XP開始得到支持。
只適用於目錄。Vista的"C:\Documents and Settings\"是指向"C:\Users\"的
junctionpoint,這樣一些使用了硬編碼"C:\Documents and Settings\"的老程序可
以在Vista上正常工作。
只能使用絕對路徑。即使創建junction point時使用了相對路徑,保存到NTFS中時將
隱式轉換成絕對路徑。
junction point必須與target directory位於同一local computer,可以簡單理解成
不能跨主機。不能使用UNC路徑;假設Z是通過網絡映射生成的盤符,同樣不適用於Z。
在local computer範圍內,可以跨盤符。
在Explorer中刪除junction point,有兩種情況。對於Windows 2000/XP/2003,會同
步刪除target directory,這真是一個奇葩的行爲。注意,我們強調,在Explorer中
刪除,高版本的Total Commander沒有這個奇葩行爲。對於Vista及之後版本,不影響
target directory,這纔是人類所能理解的行爲。
刪除target directory,junction point仍將存在,但失效了,變得不可用。這個很
好理解,因爲此時junction point指向不存在的目錄。
diskmgmt.msc
右鍵選中某volume
更改驅動器號和路徑
添加
裝入以下空白NTFS文件夾中
這個功能用的就是junction point機制,還可以用mountvol.exe完成操作。
創建:
mklink /J "junctionpoint name" "targetdirectory" // 生成的Reparse Data相比junction.exe要多
linkd.exe "junction pointname" "targetdirectory" // Windows Resource Kits
查看:
dir /A:L /S "path"
fsutil.exe reparsepoint query "junctionpoint name" // 有Reparse Data的16進制轉儲
linkd.exe "junction pointname" // 不能查看junction.exe生成的"junctionpoint"
刪除:
fsutil.exe reparsepoint delete "junctionpoint name" // 不建議使用
linkd.exe "junctionpoint name" /D // 可以刪除junction.exe生成的"junctionpoint"
它這個行爲不是我們期望的效果,比如"targetdirectory"下有普通文件,上述命令
會刪除"junction point"下的普通文件,但不會刪除"junctionpoint",同時
"targetdirectory"下的普通文件仍然存在。這個效果我不能理解。在Explorer中操
作無法達到這種效果。
sysinternals的junction.exe:
junction.exe "junction point name" "targetdirectory" // 創建
junction.exe "junctionpoint name" // 查看
junction.exe -q -s "path" // 遞歸查看
junction.exe -d "junctionpoint name" // 刪除
我猜junction.exe提供-d參數,就是因爲Windows 2000/XP/2003的Explorer奇葩行爲,
這個-d不影響target directory。
示例:
"dir/A:L/Sc:\
2009/07/14 13:08 "JUNCTION" Documents andSettings [C:\Users]
"junction.exe "C:\Documentsand Settings"
C:\Documents and Settings: JUNCTION
Print Name : C:\Users
Substitute Name: C:\Users
"junction.exe-q-sc:\
\\?\c:\\Documentsand Settings:JUNCTION
Print Name : C:\Users
Substitute Name:C:\Users
--------------------------------------------------------------------------
4)symbolic link
SymbolicLinks
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365680
symbolic link不是softlink,不要跟着SB瞎起鬨。
NTFS內置機制,從Vista開始得到支持。
同時適用於文件、目錄。這是一種超級shortcut。
可以使用相對、絕對路徑。假設創建symbolic link時使用了相對路徑,保存到NTFS
中的就是相對路徑,不會隱式轉換成絕對路徑。
可以跨盤符,可以跨主機,可以使用UNC路徑、網絡驅動器。
在Explorer中刪除symboliclink,不影響target。
刪除target,symboliclink仍將存在,但失效了,變得不可用。
相關Win32API:
CreateSymbolicLink()
CreateSymbolicLinkTransacted()
創建:
mklink "file symbolic link name""target file"
mklink/D"directory symbolic link name""target directory"
注意不指定/D時創建filesymbolic link,指定/D創建directorysymbolic link。
--------------------------------------------------------------------------
轉載請註明:“轉自綠盟科技博客”:http://blog.nsfocus.net/shortcuthard-linkjunction-pointsymbolic-link/