Oh. Look. It's my blog - isn't that exciting?
Warning: Author isn't much of a writer. ^.^
Published on November 17, 2003 By kthxbye In Personal Computing

Thanks to Microsoft providing APIs, but not providing any utility-level support (such as Unix's 'ln' command,) few people today are aware of the fact that Windows provides file system level support for both POSIX compliant hard links for files as well as Microsoft's own form of symbolic links through shell links and (on NTFS 5 or higher,) junction points for directories. Instead, they've offered to hype their own shortcuts (which are nothing more than a generic, meaningless .lnk file,) to the end user.

What is a symbolic link?
"A symbolic link is an entry in a Unix (or Unix-like) filesystem that allows a directory entry to refer to another directory entry." - wikipedia.org

Shell Links

Sounds like a shortcut, right? In essence, they're quite similar in function - however Windows' shell links provide this functionality, as well as a lot more. Both allow you to access a folder (say C:\this\is\a\really\long\and\annoying\directory\) in a more useful way (such as a direct link to \directory\ on your C:\ drive. However, if you use explorer with the folder pane open, we quickly run into a rather larger limitation of shortcuts. In the screenshot I've created both a shell link ([muzik]) and a shortcut to a folder on my d:\ drive.

The first result should be obvious quite quickly. Explorer does not show shortcuts to directories in the folder pane! The shell link however, shows up beautifully. Also shown is the properties for the shell link. Windows realizes it's a folder but it also realizes that it's a linked folder.
Shell links do have one significant drawback however. Console windows. If you were to open up cmd.exe (or command.com for you out-of-date users,) and switch to a linked directory, you might notice something surprising:

That's right. The link is actually created through the rather tricky usage of an empty directory and a special kind of .lnk file! An interesting side effect of this, is that if you rename the linked directory, the shell link simply disappears from it's location. If I were to rename D:\music to D:\foo - the [muzik] link on my desktop in the above picture would simply vanish.

Junction Points

Junction points - a feature of NTFS on Windows 2000 and higher, are a bit more featured, and also, a bit more dangerous to use. Used correctly though, they're also a wonderful feature. The WinbolicLink help file says it far better than I ever could, so I will simply use their explanation of a junction:

"Junctions, for all intents and purposes, are invisible to Windows. Virtually all programs, including Windows Explorer, will interpret the linked folder as though it were the target folder. This makes Junctions dangerous because deleting the link in a non-junction-aware program such as Explorer will cause a recursive delete, deleting the contents of the target folder as well as the link."

Yes. If you delete a link to a junctioned folder, even in explorer, you will most likely wind up deleting the actual folder itself. Junctions do have their uses though - the most evident is when running low on disk space. What do you do if you're running low in disk space on your primary drive, but you have a second drive with plenty of available space? Using junctions, /without uninstalling/ programs, you can actually move, say, programs in your C:\program files\ folder over onto your D:\ drive.

Through a junction point, you could move, for example, C:\program files\stardock\ to D:\programs\stardock\ and then create a junction pointing d:\programs\stardock\ back to c:\program files\stardock\. Even though those program files now physically reside on your D:\ drive, to Windows, and all programs, they are still viewed as residing in the original directory.

Junctions are also implemented on a kernel level - offering up theortecial performance increases versus a shell link (though, I've never noticed any degredation with a regular link, which is what I use.)

Winbolic Link is a wonderful, and free, package for creating and maintaining shell links and junctions with windows.

Hard Links

A hard link is essentially the same thing, only with files. In essence, it's having more than one directory entry pointing to the same file. So, if you have c:\foo.txt and d:\bar.txt - you can edit, change, etc. either file - and the changes show up immediately in the other. Very similar to a file shortcut, but on a system level.

A big advantage over a shortcut however, is that you can rename, move, or do whatever you wish to a hard linked file (either the link, or the original,) and they will always point to the same data. And as a hard link is just another directory entry, you can even delete the original file - and the hard link will still contain the data.

To delete a hard linked file, you have to delete all references (original & links,) to the file.

A good example of uses for hardlinks would be for a developer who has 10+ copies of the /exact/ same files for different projects sitting in 10 different spots on his harddrive, all using up space. As the files are identical, she could just keep one copy of the file on her drive, and hard link it to all of the other directories she needs.

(Yes, not as much to say about hard links - they simply aren't nearly as useful for my needs and usage. They're still handy, however.)

A good package for hard links exists as well: Hard Link Magic - they can also be created from the console with the fsutil command - but it's a cumbersome beast.

EDIT: For some reason, my images aren't showing up correctly (at least on my end.) by default. Firebird (and possibly mozilla,) users can right click on them and choose "View Image" - and they display fine, even when you 'back' to the article. IE users... from my quick testing, you're out of luck.


Comments
on Dec 07, 2003
Thanks for writing an informative. Not sure who you are writing it for, though. It's about links on Windows, but 99% of people using Windows who are using IE can't see the images. Too bad you wasted your time. And mine.
on Dec 08, 2003
Actually, the image links are the ones I was talking about IE users being unable to see - perhaps I wasn't quite clear enough in that regard? Not a surprise as not only am I not a professional writer, but I can only barely be considered an amateur one too. ^.^

The problem with the image links stems from the hosting provider that's serving them for me - aparantly, they're like many, and don't allow direct linking to images, that's all. In Firebird, it's easy to work around - in MSIE I couldn't find an easy way to do it (Though I suppose cutting and pasting the link would have worked - if I were able to bring up MSIE right now, I'd check - but I can't, so... well, I won't? ^.^)
on Dec 20, 2003
Great article, very informative. I'm disappointed that you can not create a hard link across logical drives with magic link. Are there other products that do this, or is this not the purpous of a hard link?
on Aug 03, 2005
Honestly, get a unix box (freebsd works fine) for anything that needs symlinks. Just ask your friends to bring their junk computers to you instead of throwing them out, those things make great server boxes.