For a long time Linux and Unix have had the marvellous ability of allowing user created links on their file systems. These links are file and folder pointers that are sorted and registered by the operating system file partition. But unlike the more common Microsoft Windows short-cut, programs that encounter user created links will treat them as the source file or folder.
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 as the W: drive. This allows me to optimise searches and backups as well as keeping the partition more secure from potential problems.
Part of my work involves web development and for testing often the files I am working with need to be located within a web server’s root directory. But this can be problematic if the server application is installed on the C: drive. So a hard link is useful as I can create a pointer from the server root directory and target it to the folder containing the project files on the W: work drive. Once the project is completed the hard link can be removed which would sever the link to the testing web server without the need to move any files.
The Windows NTFS file system has supported some form of file and directory pointing since Windows 2000. Unfortunately each revision of Windows until Windows Vista has used a different method of implementing these pointers. So for this article I will just focus on Windows Vista and the identical Windows 7/8 implementations.
In Windows what is the difference between a short-cut, a symbolic link (sym-link) and a hard link?
A short cut is a file that points to another file. It is an antiquated pointing system from the Windows 95 era that many programs do not recognise. Short-cuts do not only use up space on the hard drive, they also break and linger behind after the target has been deleted, renamed or moved.
A symbolic link is like a short-cut but instead of being saved as a file it is registered to the hard drive partition. It does not use any disk space and all programs recognise both the link and the target. A symbolic link can point to any file or folder either locally on the computer or over a network using a SMB path.
A file hard link is a little different and can not be used over multiple partitions meaning you can not have a link on drive C: pointing to a file on drive D:. A file hard link points to and duplicates a target as a mirrored copy but the copy does not use any additional space on the hard drive partition. So 2 hard links that mirrored a 1 GB file would in total only use 1 GB on the partition rather than 3 GB. Importantly if either the hard links or the target are deleted the other links retain the data. Changes to the content of either the target or the links automatically propagate to all other items.
is a hard link for directories but unlike file hard links you can create junctions that span multiple partitions. Again a directory junction and its content is stored on the hard drive partition but they do not use any additional space. Any changes to the content within either the target or the links will automatically propagate except where the target directory is deleted or renamed. In that case all hard links that point to the target will break and linger on the partition.
Microsoft Windows Vista, 7 and 8 use the command line program mklink to create links. It has 3 arguments and requires both a link name and target.
mklink /D /H /J [LINK NAME] [TARGET]
There are 4 modes for mklink which counteract each other so you can only use at most a single argument.
Supplying no arguments creates file symbolic link which is a pointer to a file.
/D creates a directory symbolic link which is a pointer to a directory.
/H creates a file hard link and is best used in situations where you need multiple mirrors of a file.
/J creates a directory junction which is a directory link that mirrors a the target directory over the same or on a different hard drive partition.
The word mirrors in this context means the live duplication of the target and the links. Any changes to the structure or the content of any files or any directories will propagate instantly to all links and to the target.
mklink /J WindowsVista C:\Windows
This command would create a directory junction WindowsVista linking (pointing) to the directory C:\Windows
Below is a screen capture of the 4 different types of links . The yellow is a hard file link that does not consume any additional hard drive space. The blue is a symbolic link to a file. The green is a symbolic link to a
file . While the red is a hard link to a directory which is commonly known as a directory junction.