感謝㊣贊助鼓勵!

Google搜尋 »

分類

簡睿在噗浪»

有朋自遠方來

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

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="">

隨機文章

  1. [Tools] 檔案總管工具:2xExplorer和xplorer² 
  2. [Java] 終於解決IntelliJ-IDEA 8.0.1的中文輸入法問題 (7)
  3. 簡單比一比:funP麻吉與豆瓣網 
  4. [Windows] 以Shell命令開啟系統目錄 (1)
  5. 閱讀《矽谷大革命》 
  6. Xuite 浮光掠影的映像介紹 
  7. 樂多Blog試貼 (1)
  8. [Sites] HiNet 「我的便利貼」V2.0 搶鮮試用中 
  9. 使用Word 2010 Beta/2007寫Blog文章 (6)
  10. Picasa 圖片整理工具 

歷史熱門文章

  1. Plurk CSS樣式自訂修改全攻略 (30,962 點擊/2009-07-04)
  2. 把HTC Touch HD操作介面換成Spb Mobile Shell,美觀又便利! (20,275 點擊/2009-02-18)
  3. 強化閱讀第2噗:變更噗浪回應的字體與背景顏色 (17,548 點擊/2009-06-07)
  4. 另一套適用手機的影片轉檔工具:WinAVI 3GP/MP4/PSP/iPod Video Converter (16,754 點擊/2009-04-18)
  5. 強化HTC Touch HD的工具軟體 (14,973 點擊/2009-02-25)
  6. 如何手動輸入Plurk的表情圖示? (13,960 點擊/2008-09-29)
  7. 增加Spb Mobile Shell 3.0生活化桌面頁數的小技巧 (13,744 點擊/2009-04-27)
  8. 簡單放大Plurk輸入區的方法[修訂] (13,049 點擊/2008-09-29)
  9. 將Plurk回應區變成固定寬度 (12,874 點擊/2009-07-11)
  10. 將噗浪的視窗高度變大,加上分隔線,以方便閱讀 (12,515 點擊/2009-06-06)