Create Symbolic Links, Hard Links and Directory Junctions in Vista with MKLINK

For Unix-like or Linux system users, symbolic link is a common feature in use almost daily. Symbolic link (aka soft link) or symlink as it often shortened to, is a special type of file or file-system object that serves as a reference or points to another file, UNC or directory, known as target. In Windows Vista, symlinks feature has been added to NTFS filesystem and can be created by using MKLINK command. In previous Windows operating system, the closer thing to symbolic links is NTFS junction point, or worse, Windows shell shortcut (.lnk) file.

Symlink in Vista, unlike .lnk shortcut in desktop or Windows Explorer, allow user to access files within the symbolic link created itself via explorer, the console and etc. And symbolic link also differ from NTFS junction point which can only link to folders and volumes, in which symlinks can point to a file, a UNC, a folder or a volume, as well as able to span file systems.

Symbolic link is useful when you have a lot of folders and files are scattered all over the directory tree, and you need to manage them from a single location. Another scenario is that you have a deep nested file that you want to access quickly instead of traverse through one branch by one branch. And furthermore, for programmer, symlink provides a static file path that can be point to a ever changing object without affecting the functionality of the program. In all these situation, symbolic links can be created at a convenient location which point to the ‘real’ objects.

As mentioned, to create a symbolic link, use MKLINK command line tool. MKLINK can be used to create a hard link or directory junction too. Hard link is essentially giving another name or label to the objects, while NTFS directory junction point is used to redirect the whole folder to another folder as if it’s the original folder itself. Junction point is used extensively in Vista to provide support for old directory structures for user profiles (i.e Documents and Settings) to point to the new user folders located inside Users directory.

Syntax and Options of MKLINK

MKLINK [[/D] | [/H] | [/J]] Link Target

/D - Creates a directory symbolic link. Default to file symbolic link.
/H - Creates a hard link instead of a symbolic link.
/J - Creates a Directory Junction.
Link - Specifies the new symbolic link name.
Target - Specifies the path (relative or absolute) that the new link refers to.

Examples and Usages of MKLINK

Note: Only Administrators can use MKLINK to create symbolic links unless override by using secpol.msc, so you need to run Command Prompt with elevated privileges, or else you will get “You do not have sufficient privilege to perform this operation.” error.

To create symbolic link called foo to reference to c:\Windows\System32\notepad.exe:

C:\test>mklink foo c:\Windows\System32\notepad.exe

You will see the following result:

symbolic link created for foo <<===>> c:\Windows\System32\notepad.exe

If you type dir in commnd prompt, you will see the following listing:

Volume in drive C has no label.
Volume Serial Number is 2211-7428

Directory of C:\test

04/14/2006 11:24 AM <DIR> .
04/14/2006 11:24 AM <DIR> ..
04/14/2006 11:24 AM <SYMLINK> foo [c:\Windows\system32\notepad.exe]
1 File(s) 0 bytes
2 Dir(s) 69,238,722,560 bytes free

To create symbolic link to a folder, simply use /D switch:

C:\test>mklink /d bar c:\windows
symbolic link created for bar <<===>> c:\windows

Results of dir command:

Volume in drive C has no label.
Volume Serial Number is 2211-7428

Directory of C:\test

04/14/2006 11:24 AM <DIR> .
04/14/2006 11:24 AM <DIR> ..
04/14/2006 11:24 AM <SYMLINKD> bar [c:\windows]
04/14/2006 11:24 AM <SYMLINK> foo [c:\Windows\system32\notepad.exe]
1 File(s) 0 bytes
3 Dir(s) 69,238,722,560 bytes free

MKLINK cannot use to delete symbolic link. To remove a symbolic link, simply delete them as if you’re removing a normal file. For example, to delete the foo symbolic link created above, enter the following command:

C:\test>del foo

To remove the bar symbolic link to a folder created above, use the following command:

C:\test>rd bar

Share and contribute or get technical support and help at My Digital Life Forums.



4 Responses to “Create Symbolic Links, Hard Links and Directory Junctions in Vista with MKLINK”

  1. The CTRAN weblog » Blog Archive » Create Symbolic Links, Hard Links and Directory Junctions in Vista with MKLINK
    June 2nd, 2007 04:22
    1

    [...] Create Symbolic Links, Hard Links and Directory Junctions in Vista with MKLINK ยป My Digital Life: [...]

  2. david
    June 23rd, 2008 09:36
    2

    I cannot figure out how to go to or switch to a symbolic link after it is created. How do you do it? I can’t find instructions for this mentioned anywhere.

  3. Ed
    June 25th, 2008 06:32
    3

    Thanks for the post, but I don’t see the point of creating a symlink to a file. In your example, you created a symlink called “foo” pointing to notepad.exe, but what can you do to the file “foo”? It’s not executable, even after I rename it to foo.exe.

    Thanks.

  4. ludo
    July 22nd, 2008 17:39
    4

    you can’t execute symlinks, for that you need to make a shortcut the normal way. A symlink is more usefull for ppl to read a certain file wich is in a folder they normaly can’t go to. Or the same file is needed on 2 different folder locations, but you dont want to edit 2 seperate files all the time.

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting


Custom Search

New Articles

Incoming Search Terms for the Article

mklink - vista hard link - mklink vista - mklink download - vista hard links - download mklink - vista create junction - vista Hardlink - vista mklink - vista create link - vista junctions - hard link vista - mklink remove - remove symbolic link vista - create link vista - vista directory link - remove symbolic link - mklink junction - hard links vista - mklink syntax - mklink hard link - vista create hard link - create junction vista - windows vista hard link - windows vista hard links - remove mklink - delete mklink - create hard link vista - mklink delete - MKLINK - vista make link - all - create symbolic link vista - vista remove symbolic link - how to use mklink - mklink you do not have sufficient privilege to perform this operation - mklink windows xp - mklink privileges - link folder vista - vista directory links - create ntfs junction vista - delete junction vista - vista mklink privileges - hard link directory - hard link windows vista - symbolic link Vista - vista junction create - vista mklink remove - vista delete symbolic link - junction mklink -