mklink是Windows 7下的一個類似於linux下In的命令,其作用是在NTFS文件系統中創建文件或目錄的鏈接(類似於桌面快捷方式)。如果加以利用其發揮的作用是非常的大的,不僅可以幫助我們節省不少時間,而且可以使我們重裝系統後不再丟失用戶文件。
Mklink命令詳細介紹 |
Windows 7下的mklink命令通過指定參數可以建立出不同形式的文件或目錄鏈接,分為 hard link、symbolic link 和junction 三種。
1.symbolic link
A symbolic link is like a short-cut but instead of being saved as a file it is registered to the hard drive partition. It does not use any disk space and all programs recognise both the link and the target. A symbolic link can point to any file or folder either locally on the computer or over a network using a SMB path. ( A short cut is a file that points to another file. It is an antiquated pointing system from the Windows 95 era that many programs do not recognise. Short-cuts do not only use up space on the hard drive, they also break and linger behind after the target has been deleted, renamed or moved. )
2.junction
作用基本和 symbolic link 類似。區別在於,junction 在建立時會自動引用原文件(或目錄)的絕對路徑, 而 symbolic link 允許相對路徑的引用。A junction behaves like a hard link for directories but unlike file hard links you can create junctions that span multiple partitions. Again a directory junction and its content is stored on the hard drive partition but they do not use any additional space. Any changes to the content within either the target or the links will automatically propagate except where the target directory is deleted or renamed. In that case all hard links that point to the target will break and linger on the partition.
3.hard link
建立一個 hard link 相當於給文件建立了一個別名,例如對1.TXT創建了名字為2.TXT的硬鏈接,若使用記事本對1.TXT進行修改,則2.TXT也同時被修改,若刪除1.TXT,則2.TXT依然存在,且內容與1.TXT一樣。 A file hard link is a little different and can not be used over multiple partitions meaning you can not have a link on drive C: pointing to a file on drive D:. A file hard link points to and duplicates a target as a mirrored copy but the copy does not use any additional space on the hard drive partition. So 2 hard links that mirrored a 1 GB file would in total only use 1 GB on the partition rather than 3 GB. Importantly if either the hard links or the target are deleted the other links retain the data. Changes to the content of either the target or the links automatically propagate to all other items.
建立鏈接請注意:
1、建立文件或目錄鏈接限於 NTFS 文件系統,symbolic (junction) link 的建立可以跨文件系統;
2、hard link 只能用於文件,不能用於目錄,symbolic (junction) link 可以為目錄建立鏈接;
3、hard link 只能建立同一分區內的文件指向;
4、hard link 不允許對空文件建立鏈接,symbolic (junction) 可以。
Mklink的參數定義 |
無參數指定:建立文件的符號鏈接。無參數指定的默認情況下,建立的是文件的符號鏈接,刪除鏈接文件不會影響源文件,
/d:建立目錄的符號鏈接符號鏈接(symbolic link)
/j:建立目錄的軟鏈接(聯接)(junction)
/h:建立文件的硬鏈接(hard link)
命令格式:mklink /d(定義參數) \MyDocs(鏈接文件) \Users\User1\Documents(原文件)
最後,至於刪除建立的鏈接,跟刪除文件一樣使用」DEL」命令。
Mklink命令用途 |
轉移系統中的用戶設置文件
Windows 7中將用戶設置與系統文件分離, 所有的用戶設置及用戶文件都存儲在C盤下的User目錄 (在中文版Windows 7中顯示為「用戶」目錄), 重裝系統後所有的系統設置及用戶文件都會消失。
Windows 7安裝完成後可以將C盤下的User目錄轉移到非系統分區,如D盤,這樣,重裝系統後只要重新將C盤下的User目錄鏈接到D盤即可。我們在創建鏈接後系統在訪問C:/User目錄其實是在訪問D:/User目錄。
命令如下:
1.複製User目錄到D盤 : robocopy 「C:\Users」 「D:\Users」 /E /COPYALL /XJ
2.強制刪除User目錄 : rmdir 「C:\Users」 /S /Q
3.創建C盤下的User的軟件鏈接,鏈接到D盤User目錄:mklink /J 「C:\Users」 「D:\Users」
重裝系統後只需重覆第二條和第三條命令及可
有了這條命令就再也不怕重新系統了