I imagine all my geek friends already know about this, but I just typed this up for work and figured it wouldn't hurt to put it here too.
In the modern Windows platform (e.g. Windows XP or Windows 2000 or greater using NTFS), it is possible to create hardlinks of files and directories. The ability to create file hardlinks is built into XP/W2k with the program fsutil.exe.
fsutil hardlink create Usage : fsutil hardlink create <new filename> <existing filename>Anything written to foo.txt will appear in bar.txt and vice versa. If one file is deleted, the other remains.Eg : fsutil hardlink create c:\foo.txt c:\bar.txt
- (Note that some editors have a backup feature that can interfere with hardlinks. e.g. vim. When you make changes to a file with an editor using the backup feature, the editor actually renames the existing file and then writes a completely new file with the updated contents. This will make your hardlink non-functional. The hardlink is still there and working fine, but it is now a hardlink to the backed up file and the changes you just made will not be written to the other hardlinks of that file. This behavior in vim can be fixed by setting backupcopy=yes)
Directory hardlinks in Windows are called Junctions (a special type of Reparse Point). Support for junctions is built into XP/W2k, but they don't have a utility such as fsutil that can create them installed by default.
- (Note that deleting a junctioned folder in Windows Explorer is BAD. Explorer will traverse the folder deleting all files within that folder which will result in those files being deleted from the other folder! If you want to get rid of the junction, use the delete function of the junction or linkd utility.)
- junction.exe -- Available from the Sysinternals Website
- Create Usage: junction newdirname existingdirname
- Delete Usage: junction -d newdirname
- Show Target Usage: junction newdirname
- linkd.exe -- Available from the Windows 2003 resource kit (but runs on XP too)
- Create Usage: linkd newdirname existingdirname
- Delete Usage: linkd newdirname /D
- Show Target Usage: linkd newdirname
There is also a Windows Explorer shell extension that allows you to create hardlinks and junctions from within Explorer.
![[info]](http://l-stat.livejournal.com/img/userinfo.gif)


2006-02-16 05:09 am (UTC)