What are the various link types in Windows? How do I create them?
Please note that the only unfortunate difference is that you need Administrator rights to create symbolic links. IE, you need an elevated prompt. (A workaround is the SeCreateSymbolicLinkPrivilege can be granted to normal Users via secpol.msc
.)
Note in terminology: Windows shortcuts are not called "symlinks"; they are shell links, as they are simply files that the Windows Explorer shell treats specially.
Symlinks: How do I create them on NTFS file system?
Windows Vista and later versions support Unix-style symlinks on NTFS filesystems.
Remember that they also follow the same path resolution – relative links are created relative to the link's location, not to the current directory. People often forget that. They can also be implemented using an absolute path; EG c:\windows\system32 instead of \system32 (which goes to a system32 directory connected to the link's location).
Symlinks are implemented using reparse points and generally have the same behavior as Unix symlinks.
For files you can execute:
mklink linkname targetpath
For directories you can execute:
mklink /d linkname targetpath
Hardlinks: How do I create them on NTFS file systems?
All versions of Windows NT support Unix-style hard links on NTFS filesystems. Using mklink on Vista and up:
mklink /h linkname targetpath
For Windows 2000 and XP, use fsutil
.
fsutil hardlink create linkname targetpath
These also work the same way as Unix hard links – multiple file table entries point to the same inode.
Directory Junctions: How do I create them on NTFS file systems?
Windows 2000 and later support directory junctions on NTFS filesystems. They are different from symlinks in that they are always absolute and only point to directories, never to files.
mklink /j linkname targetpath
On versions which do not have mklink
, download junction
from Sysinternals:
junction linkname targetpath
Junctions are implemented using reparse points.
How can I mount a volume using a reparse point in Windows?
For completeness, on Windows 2000 and later, reparse points can also point to volumes, resulting in persistent Unix-style disk mounts:
mountvol mountpoint \\?\Volume{volumeguid}
Volume GUIDs are listed by mountvol
; they are static but only within the same machine.
Is there a way to do this in Windows Explorer?
Yes, you can use the shell extension Link Shell Extension which makes it very easy to make the links that have been described above. You can find the downloads at the bottom of the page.
The NTFS file system implemented in NT4, Windows 2000, Windows XP, Windows XP64, and Windows7 supports a facility known as hard links (referred to herein as Hardlinks). Hardlinks provide the ability to keep a single copy of a file yet have it appear in multiple folders (directories). They can be created with the POSIX command ln included in the Windows Resource Kit, the fsutil command utility included in Windows XP or my command line ln.exe utility.
The extension allows the user to select one or many files or folders, then using the mouse, complete the creation of the required Links - Hardlinks, Junctions or Symbolic Links or in the case of folders to create Clones consisting of Hard or Symbolic Links. LSE is supported on all Windows versions that support NTFS version 5.0 or later, including Windows XP64 and Windows7. Hardlinks, Junctions and Symbolic Links are NOT supported on FAT file systems, and nor is the Cloning and Smart Copy process supported on FAT file systems.
The source can simple be picked using a right click menu.
And depending on what you picked, you right click on a destination folder and get a menu with options.
This makes it very easy to create links. For an extensive guide, read the LSE documentation.
Downloads can be found at the bottom of their page.
Relevant MSDN URLs:
- Reparse Points
- Hardlinks and Junctions
- Symlinks
In this answer I will attempt to outline what the different types of links in directory management are as well as why they are useful as well as when they could be used. When trying to achieve a certain organization on your file volumes, knowing the various different types as well as creating them is valuable knowledge.
For information on how a certain link can be made, refer to grawity's answer.
What is a link?
A link is a relationship between two entities; in the context of directory management, a link can be seen as a relationship between the following two entities:
Directory Table
This table keeps track of the files and folders that reside in a specific folder.
A directory table is a special type of file that represents a directory (also known as a folder). Each file or directory stored within it is represented by a 32-byte entry in the table. Each entry records the name, extension, attributes (archive, directory, hidden, read-only, system and volume), the date and time of last modification, the address of the first cluster of the file/directory's data and finally the size of the file/directory.
Data Cluster
More specifically, the first cluster of the file or directory.
A cluster is the smallest logical amount of disk space that can be allocated to hold a file.
The special thing about this relationship is that it allows one to have only one data cluster but many links to that data cluster, this allows us to show data as being present in multiple locations. However, there are multiple ways to do this and each method of doing so has its own effects.
To see where this roots from, lets go back to the past...
What is a shell link and why is in not always sufficient?
Although it might not sound familiar, we all know this one! File shortcuts are undoubtedly the most frequently used way of linking files. These were found in some of the early versions of Windows 9x and have been there for a long while.
These allow you to quickly create a shortcut to any file or folder, they are more specifically made to store extra information along just the link like for example the working directory the file is executed in, the arguments to provide to the program as well as options like whether to maximize the program.
The downside to this approach of linking is exactly that, the extra information requires this type of link to have a data cluster on its own to contain that file. The problem then is not necessarily that it takes disk space, but its rather that it the link is indirectly accessed as the Data Cluster first has to be requested before we get to the actual link. If the path referred to in the actual link is gone the shell link will still exist.
If you were to operate on the file being referred to, you would actually first have to figure out in which directory the file is. You can't simply open the link in an editor as you would then be editing the .lnk
file rather than the file being linked to. This locks out a lot of possible use cases for shell links.
How does a junction point link try to solve these problems?
A NTFS junction point allows one to create a symbolic link to a directory on the local drives, in such a way that it behaves just like a normal directory. So, you have one directory of files stored on your disk but can access it from multiple locations.
When removing the junction point, the original directory remains. When removing the original directory, the junction point remains. It is very costly to enumerate the disk to check for junction points that have to be deleted. This is a downside as a result of its implementation.
The NTFS junction point is implemented using NTFS reparse points, which are NTFS file system objects introduced with Windows 2000.
An NTFS reparse point is a type of NTFS file system object. Reparse points provide a way to extend the NTFS filesystem by adding extra information to the directory entry, so a file system filter can interpret how the operating system will treat the data. This allows the creation of junction points, NTFS symbolic links and volume mount points, and is a key feature to Windows 2000's Hierarchical Storage System.
That's right, the invention of the reparse point allows us to do more sophisticated ways of linking.
The NTFS junction point is a soft link, which means that it just links to the name of the file. This means that whenever the link is deleted the original data stays intact; but, whenever the original data is deleted the original data will be gone.
Can I also soft link files? Are there symbolic links?
Yes, when Windows Vista came around they decided to extend the functionality of the NTFS file system object(s) by providing the NTFS symbolic link, which is a soft link that acts in the same way as the NTFS junction point. But can be applied to file and directories.
They again share the same deletion behavior, in some use cases this can be a pain for files as you don't want to have an useless copy of a file hanging around. This is why also the notion of hard links have been implemented.
What is a hard link and how does it behave as opposed to soft links?
Hard links are not NTFS file system objects, but they are instead a link to a file (in detail, they refer to the MFT entry as that stores extra information about the actual file). The MFT entry has a field that remembers the amounts of time a file is being hard linked to. The data will still be accessible as long as at least one link that points to it still exists.
So, the data does no longer depend on a single MFT entry to exist. As long as there is a hard link around, the data will survive. This prevents accidental deleting for cases where one does not want to remember where the original file was.
You could for example make a folder with "movies I still have to watch" as well as a folder "movies that I take on vacation" as well as a folder "favorite movies". Movies that are none of these will be properly deleted while movies that are any of these will continue to exist even when you have watched a movie.
What is a volume mount point link for?
Some IT or business people might dislike having to remember or type the different drive letters their system has. What does M:
really mean anyway? Was it Music? Movies? Models? Maps?
Microsoft has done efforts over the year to try to migrate users away from the work in drive C:
to work in your user folder
. I could undoubtedly say that the users with UAC and permission problems are those that do not follow these guidelines, but doesn't that make them wonder:
Why should you even be viewing anything but your personal files on a daily basis?
Volume mount points are the professional IT way of not being limited by drive letters as well as having a directory structure that makes sense for them, but...
My files are in different places, can I use links to get them together?
In Windows 7, Libraries were introduced exactly for this purpose. Done with music files that are located in this folder, and that folder and that folder. From a lower level of view, a library can be viewed as multiple links. They are again implemented as a file system object that can contain multiple references. It is in essence a one-to-many relationship...
My brain explodes... Can you summarize when to use them?
Shortcut links: Use them when you need quick access to an executable or website, a file that you launch very often or when you need to specify parameters to an application and a batch file is an overkill. Don't use it when you intend to manipulate the file through its shortcut.
Junction points: Use them when you want a directory to be elsewhere, this allows you to move directories to faster or slower drives without losing the ability to access the original path. Another use is when you want access to a directory through another path. These can't be used to link to a share.
Soft links: Use them where a shortcut link does not suffice, it is often used when you do intend to manipulate the file through its shortcut. Or when you want the file to be on a faster or slower drive without losing the ability to access the original path.
Hard links: Use them when you only want a file to be gone when all hard links to it are removed. This can't be used for folders.
Volume mount points: Use them when you run out of drive letters, or when you find it more feasible to access a volume through a path rather than through a drive letter.
Libraries: Use them when you have the same type of file at many different locations and you need them to be together, this supports removable drives so makes it handy to get the folders on your removable drives show up between those on your computer when you insert it. You can click on the individual folders from the folder tree under the library in the tree view, which facilitates moving files between both.
If you're on Windows Vista or later, and have admin rights, you might check out the mklink
command (it's a command line tool). I'm not sure how symlink-y it actually is since windows gives it the little arrow icon it puts on shortcuts, but a quick notepad++ test on a text file suggests it might work for what you're looking for.
You can run mklink with no arguments for a quick usage guide.