Windows硬链接 软链接 符号链接 快捷方式


--------------------------------------------------------------------------
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/

发布了55 篇原创文章 · 获赞 29 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/ruibin_cao/article/details/95062643