Linux and Unix for a long time have had the marvellous ability for you to create hard links. For Window users unfamiliar with hard links, they not are unlike file and folder shortcuts. Except for one critical difference they are sorted and registered by the operating system’s file partition just like real files and directories. This means that unlike a shortcut, any program or application (including Windows Explorer and the Command Prompt) that looks that the hard link will always treat it the same as the original file or folder the symbolic link is pointing to.
Now this is advantageous for a number of reasons especially if you use multiple partitions on your computer. I for example keep all my work related files on a separate partition labelled with the W: drive. This allows me to optimise searches and backups as well as keeping the partition more secure from potential problems arising from operating system errors.
Part of my work involves web development and often that requires the files I am working on to be located on the web server’s root directory. This can be a problem if the web server application is installed on the C: drive. This is where a hard link is useful as I can simply create a link from the web server’s root directory and point it to the folder containing the HTML files on my work drive (W:). With the link the web server is none the wiser. Once I have finished developing, testing and troubleshooting I can remove the hard link and the web server will then assume the directory with the work has been removed. But this has been done without any directory refactoring or moving.
The Windows NTFS file system has supported some form of symbolic linking since Windows 2000. Unfortunately each revision of Windows up until Windows Vista has used a different method of implementing linking. So for this article I will just focus on the Windows Vista and the identical Windows 7 implementation.
So in Windows what is the difference between a short-cut and symbolic link (sym-link) and a hard link?
A short cut is basically a file that points to another file. It is an antiquated, pointing system from the Windows 95 era. Shortcuts not only use up space on your hard drive, they linger around after the item they are pointing to has been deleted and may break if the destination is renamed or moved.
A symbolic link is like a short cut but instead of being saved as a file, they are registered to the file system. This means they do not use hard disk space but programs recognise and can read where the link is pointing to. A symbolic link can point to any file or folder either locally on the computer and over a network using a SMB path.
A file hard link and the directory junction are a little different. It not only points to the item but duplicates it as a copy without taking up the extra hard disk space required by a clone. If you have a hard link pointing to a file then delete the original file, the hard link will still retain a copy of the clone. One limitation of the file hard link is that the link can only be made on the same file partition as the file.
Finally a junction is a hard link for directories. To me they are the most useful and unlike their file hard links counterparts you can create junctions on different partitions. Again a junction is stored on the file system where it does not take up additional space and is treated by the operating system and programs as a local folder.
Windows Vista/7 uses the command line program called mklink to create these symbolic links. It has 3 arguments and then requires both a link name and target.
mklink /D /H /J [LINK NAME] [TARGET]
There are 4 modes for mklink and they all counteract each other meaning you can only use one argument or none at all.
No arguments creates file symbolic link which is like a shortcut that is registered on the file system instead of stored in a file.
/D creates a directory symbolic link which is like a shortcut that is registered on the file system instead of stored in a file.
/H creates what Windows refers to as a hard file link. A hard file link is used where you need multiple copies of a file but wish to save space by keeping only one physical copy on disk.
/J creates a Windows Junction which is a directory hard link. If you need duplicate copies of a directory but don’t wish to use up the extra hard drive space you can create a junction. Though be careful as any changes you make to a file or folder in one of the junction will affect all the others.
mklink /J WindowsVista C:\Windows
Would make a Windows Junction titled WinVista linking to the directory C:\Windows
Below is a screen capture of the 4 different types of symbolic and hard links. The yellow is a hard file link that doesn’t use up any extra hard drive space. The blue is a symbolic link to a file. The green is a symbolic link to a
The red is a hard link to a directory which is known as a Windows directory junction.