[Vista] 符號連結(Symbolic/Soft Link)、永久連結(Hard Link)與連接點(Junction Point)

mklink
Vista強化了類似Unix的符號連結(Symbolic Link,又稱Soft Link)與永久連結(Hard Link)的概念,由於我參考的網路資源大都語焉不詳,讓人越看越糊塗,因此試著以我的理解呈現出來,若有謬誤還請讀者們指正。

我們由圖形來對照不同連結的觀念。在作業系統裡要開啟任何檔案都必須先由檔案配置表(File Allocation Table,FAT,Vista裡不清楚有無別的名詞來表示)裡找到檔案項目(Entry),再由該項目查出相關屬性後,再連結到實體的內容磁區,就能讀取其檔案內容。如果我們建立一個永久連結,在FAT裡新建的連結檔名同樣會連結到內容磁區(紅線)。

  • 如果OldFileName被刪除,但因為NewHardLink仍然存在,因此其內容仍會保留在系統裡。
  • 如果修改OldFileName的內容,則因為NewHardLink也指向同一個內容磁區,因此其內容也同步變動了
  • OldFileName與NewHardLink都刪除,內容磁區才會被清除

而符號連結則只是存在於FAT裡的一個項目而已,亦即NewSoftLink是一個指向OldFileName項目的指標(藍線),如果 OldFileName被改名或刪除,則NewSoftLink就找不到內容了。
觀念清楚後,再來看Vista裡建立連結的指令。Vista裡用來建立連結的指令是mklink.exe(Make Link),使用語法如下:

  mklink [[/d] | [/h] | [/j]]
參數 說明 類型 限制
如果沒有加任何參數時,預設建立的是檔案的符號連結 捷徑
/d 建立目錄的符號連結 捷徑
/j 建錄目錄的連接點(Junction point)。 捷徑圖示,但由「內容」看並無捷徑頁籤
/h 建立檔案的永久連結。若操作對象是目錄的話會出現【存取被拒】的錯誤訊息 一般檔案 只能對本機的NTFS磁碟操作
  • :要建立的連結名稱 (圖形裡的NewHardLink與NewSoftLink)
  • :被連結的目標,可以是實體目錄或檔案的完整或部份路徑 (圖形裡的OldFileName)

範例:

  rem 檔案符號連結
  mklink c:\ln\soft-file.txt e:\USB\Project1\source\test.txt
  rem 目錄符號連結
  mklink /D c:\ln\soft-dir c:\Users\jerry\Documents
  rem 目錄永久連結
  mklink /H c:\ln\hard-file.txt c:\users\jerry\Documents\test.txt
  rem Junction Point
  mklink /J c:\ln\jp-dir c:\Users\jerry\Recent

上列指令執行後的結果:
output
永久連結和檔案符號連結建立了兩個檔案(紅框),目錄符號連結和連接點是兩個目錄,再加上目前目錄的點( . )和代表上層目錄的兩個點( .. )總共四個目錄(淺藍框)。

由檔案總管理無法很清楚的看出各種連結的類型,在DOS視窗使用dir /aL 命令才能很清楚的看到等類型。以下是使用 dir /s /aL c: 列出Vista輸出的內容。由其內容可以看出幾個重點:

  • 為了和Windows以前版本相容,C:\Documents and Settings是新建的連接點,連接目標是C:\Users
  • 連接點大量用來建立指向同一個目錄的多個名稱
 磁碟區 C 中的磁碟是 20080322
 磁碟區序號:  8C99-6FAB

 C: 的目錄

2006/11/02  21:02         Documents and Settings [C:\Users]
               0 個檔案               0 位元組

 C:\ProgramData 的目錄

2006/11/02  21:02         Application Data [C:\ProgramData]
2006/11/02  21:02         Desktop [C:\Users\Public\Desktop]
2006/11/02  21:02         Documents [C:\Users\Public\Documents]
2006/11/02  21:02         Favorites [C:\Users\Public\Favorites]
2006/11/02  21:02         Start Menu [C:\ProgramData\Microsoft\WindowsStart Menu]
2006/11/02  21:02         Templates [C:\ProgramData\Microsoft\Windows\Templates]
               0 個檔案               0 位元組

 C:\Users 的目錄

2006/11/02  21:02         All Users [C:\ProgramData]
2006/11/02  21:02         Default User [C:\Users\Default]
               0 個檔案               0 位元組

 C:\Users\All Users 的目錄

2006/11/02  21:02         Application Data [C:\ProgramData]
2006/11/02  21:02         Desktop [C:\Users\Public\Desktop]
2006/11/02  21:02         Documents [C:\Users\Public\Documents]
2006/11/02  21:02         Favorites [C:\Users\Public\Favorites]
2006/11/02  21:02         Start Menu [C:\ProgramData\Microsoft\Windows\Start Menu]
2006/11/02  21:02         Templates [C:\ProgramData\Microsoft\Windows\Templates]
               0 個檔案               0 位元組

 C:\Users\Default 的目錄

2006/11/02  21:02         Application Data [C:\Users\Default\AppData\Roaming]
2006/11/02  21:02         Cookies [C:\Users\Default\AppData\Roaming\Microsoft\Windows\Cookies]
2006/11/02  21:02         Local Settings [C:\Users\Default\AppData\Local]
2006/11/02  21:02         My Documents [C:\Users\Default\Documents]
2006/11/02  21:02         NetHood [C:\Users\Default\AppData\Roaming\Microsoft\Windows\Network Shortcuts]
2006/11/02  21:02         PrintHood [C:\Users\Default\AppData\Roaming\Microsoft\Windows\Printer Shortcuts]
2006/11/02  21:02         Recent [C:\Users\DefaultAppData\Roaming\Microsoft\Windows\Recent]
2006/11/02  21:02         SendTo [C:\Users\DefaultAppData\Roaming\Microsoft\Windows\SendTo]
2006/11/02  21:02         Start Menu [C:\Users\DefaultAppData\Roaming\Microsoft\WindowsS\tart Menu]
2006/11/02  21:02         Templates [C:\Users\Default\AppData\Roaming\Microsoft\Windows\Templates]
               0 個檔案               0 位元組

 C:\Users\Default\AppData\Local 的目錄

2006/11/02  21:02         Application Data [C:\Users\Defaul\tAppData\Local]
2006/11/02  21:02         History [C:\Users\DefaultAppData\Local\Microsoft\Windows\History]
2006/11/02
21:02         Temporary Internet Files
[C:\Users\Default\AppData\Local\Microsoft\Windows\Temporary Internet
Files]
               0 個檔案               0 位元組

 C:UsersDefaultDocuments 的目錄

2006/11/02  21:02         My Music [C:\Users\Default\Music]
2006/11/02  21:02         My Pictures [C:\Users\Default\Pictures]
2006/11/02  21:02         My Videos [C:\Users\Default\Videos]
               0 個檔案               0 位元組

 C:\Users\jerry 的目錄

2008/03/22  12:15         Application Data [C:\Users\jerry\AppData\Roaming]
2008/03/22  12:15         Cookies [C:\Users\jerry\AppData\Roaming\Microsoft\Windows\Cookies]
2008/03/22  12:15         Local Settings [C:\Users\jerry\AppData\Local]
2008/03/22  12:15         My Documents [C:\Users\jerry\Documents]
2008/03/22  12:15         NetHood [C:\Users\jerry\AppData\Roaming\Microsoft\Windows\Network Shortcuts]
2008/03/22  12:15         PrintHood [C:\Users\jerry\AppData\Roaming\Microsoft\Windows\Printer Shortcuts]
2008/03/22  12:15         Recent [C:\Users\jerry\AppData\Roaming\Microsoft\Windows\Recent]
2008/03/22  12:15         SendTo [C:\Users\jerry\AppData\Roaming\Microsoft\Windows\SendTo]
2008/03/22  12:15         Templates [C:\Users\jerry\AppData\Roaming\Microsoft\Windows\Templates]
2008/03/22  12:15         「開始」功能表 [C:\Users\jerry\AppData\Roaming\Microsoft\Windows\Start Menu]
               0 個檔案               0 位元組

 C:\Users\jerry\AppData\Local 的目錄

2008/03/22  12:15         Application Data [C:\Users\jerry\AppData\Local]
2008/03/22  12:15         History [C:\Users\jerry\AppData\Local\Microsoft\Windows\History]
2008/03/22
12:15         Temporary Internet Files [C:\Users\jerry\AppData\Local\Microsoft\Windows\Temporary Internet Files]
               0 個檔案               0 位元組

 C:\Users\jerry\AppData\Roaming\Microsoft\Windows\Start Menu 的目錄

2008/03/22  12:15         程式集 [C:\UsersjerryAppDataRoaming\Microsoft\Windows\Start Menu\Programs]
               0 個檔案               0 位元組

 C:\Users\jerry\Documents 的目錄

2008/03/22  12:15         My Music [C:UsersjerryMusic]
2008/03/22  12:15         My Pictures [C:UsersjerryPictures]
2008/03/22  12:15         My Videos [C:UsersjerryVideos]
               0 個檔案               0 位元組

 C:\Users\Public\Documents 的目錄

2006/11/02  21:02         My Music [C:\Users\Public\Music]
2006/11/02  21:02         My Pictures [C:\Users\Public\Pictures]
2006/11/02  21:02         My Videos [C:\Users\Public\Videos]
               0 個檔案               0 位元組

     檔案數目總計:
               0 個檔案               0 位元組
              51 個目錄  102,296,236,032 位元組可用

參考:

  • In Unix, what is a symbolic link, and how do I create one?
  • In Unix, what is a hard link?
  • NTFS junction point
  • Vista’s symbolic links feature saves navigating time
  • Windows的12种快捷方式(2007-4-3修訂版)

##

您可能也會有興趣的類似文章

1則留言 »[Vista] 符號連結(Symbolic/Soft Link)、永久連結(Hard Link)與連接點(Junction Point)

  • linjy Unknow Unknow

    讚~深度與實用兼具的好文章!Vista的各種秘技到處都有,都是我早已知道的內容。只有版主如此用心,發掘這種少有人知,卻非常實用的秘技!

填寫回應

 

 

 

您可使用這些HTML標籤

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

隨機文章

  1. 我常用的軟體工具彙整清單 
  2. 進階點的統計元件:JoomlaStats 
  3. 資料庫工具: Aqua Data Studio 3.7 (1)
  4. Widnows登錄壞掉了 
  5. 八里小艇地中海餐廳一遊 
  6. [News] Yahoo也要擴大Email容量到1GB了 (1)
  7. [轉貼] 为什么台湾人"现在"不认同『中国』呢?—试图以台湾的观点回答[修訂] (17)
  8. 升級中華電信50M光速上網完全設定 
  9. 動物們… 
  10. 「無名好慢???」終於消失了? (5)

歷史熱門文章

  1. 如何手動輸入Plurk的表情圖示? (352,032 點擊/2008-09-29)
  2. 簡單放大Plurk輸入區的方法[修訂] (86,779 點擊/2008-09-29)
  3. Plurk CSS樣式自訂修改全攻略 (82,771 點擊/2009-07-04)
  4. 啟用&關閉中華電信ZyXEL P874的無線網路連線功能的步驟[修訂] (82,404 點擊/2011-06-01)
  5. 網路升級光世代50M/3M與設定ZyXEL P874 (52,418 點擊/2011-05-28)
  6. 輕鬆學會彈指神功-揭露AutoHotkey絕技 (42,815 點擊/2008-04-10)
  7. iPad新手入門技巧 (39,994 點擊/2011-02-05)
  8. 分享世博台灣館主題曲『台灣的心跳聲』MV(附歌詞+下載連結+新歌詞) (38,040 點擊/2010-04-27)
  9. 把HTC Touch HD操作介面換成Spb Mobile Shell,美觀又便利! (37,863 點擊/2009-02-18)
  10. 另一套適用手機的影片轉檔工具:WinAVI 3GP/MP4/PSP/iPod Video Converter (35,797 點擊/2009-04-18)