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:
- http://www.microsoft.com/downloads/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&displaylang=en
- http://www.petri.co.il/download_windows_xp_reskit_tools.htm
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.
I think its stupid that you have to install a "Resource Kit" in order to have such basic functionality.
ReplyDeleteI was happy to discover this a while back as well.
ReplyDeleteIf 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/
Just use NTFS Link: http://elsdoerfer.name/=ntfslink
ReplyDeleteI found this on Vista the other day. This is just copy/paste from cmd. Please excuse any formatting problems.
ReplyDeleteC:\>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.
mklink works on Vista, but not on XP.
ReplyDeleteYou can do hardlinks on WinXP with Cygwin:
ReplyDelete$ cat c:/tmp/testfile
Test
$ ln c:/tmp/testfile c:/tmp/testfilelink
$ cat c:/tmp/testfilelink
Test