2009-04-27

Symbolic links in Windows

Surprisingly, all the good Windows features are hidden, undocumented and hard to find. It took me nearly a decade to accidentally find out that Windows has symbolic links. They are called NTFS Junction Points. However their support is limited to directory links, and the usage is a bit weird.

Oh, and you have to install Windows Resource Kit to get the functionality. You can download it from any of these locations:


The command you want is linkd. Let's take it for a spin.



The sandbox contains a directory named original with text.txt inside.

To create a symbolic link named symlinked that points to original, the command is linkd symlinked original. In POSIX it would be ln -s original symlinked.



When calling dir, symlinked shows as "junction". The other behavior is like a plain folder. In explorer you cannot tell the difference between the two.



To delete the symlink use rmdir, because del will attempt to remove the files from original directory.

6 comments:

  1. I think its stupid that you have to install a "Resource Kit" in order to have such basic functionality.

    ReplyDelete
  2. I was happy to discover this a while back as well.

    If you don't want to have to install the Windows Resource Kit, there's a sysinternals based command line tool for doing this as well - described here :

    http://caffeineinduced.wordpress.com/2009/03/28/a-way-to-get-true-symbolic-links-on-windows/

    ReplyDelete
  3. Just use NTFS Link: http://elsdoerfer.name/=ntfslink

    ReplyDelete
  4. I found this on Vista the other day. This is just copy/paste from cmd. Please excuse any formatting problems.



    C:\>mklink /?
    Creates a symbolic link.

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

    /D Creates a directory symbolic link. Default is a 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.

    ReplyDelete
  5. mklink works on Vista, but not on XP.

    ReplyDelete
  6. You can do hardlinks on WinXP with Cygwin:

    $ cat c:/tmp/testfile
    Test
    $ ln c:/tmp/testfile c:/tmp/testfilelink
    $ cat c:/tmp/testfilelink
    Test

    ReplyDelete

Spam comments (i.e. ones that contain links to web development services) will be reported along with user profiles!

Note: only a member of this blog may post a comment.