Compared to Linux, Symbolic Links (Symlinks) are a fairly new addition to Windows, first introduced in Windows Vista. They have been present ever since.
Unfortunately, most people don’t know anything about symlinks. Let us take a look at what symlinks are and how to use symlinks in Windows 10.
Symbolic links are shortcuts on steroids. In other words, they act just like regular shortcuts, but they are much more powerful. For instance, when you set up a symbolic link to a file, you can fool programs into thinking the file exists at a location that it doesn’t exist at.
There are two main types of symbolic links on Windows: Hard Links and Soft Links. Unlike Linux, only soft links are called symlinks in Windows.
If you hard-link a file or a folder in location A to a file or a folder in location B, the file or folder at location B would appear as though it exists at location A.
For example, let’s assume that we have a text file called «sample.txt» in the C:Programs directory. If I hard link sample.txt to a file named «test.txt,» the OS will treat test.txt as though it was sample.txt.
Essentially, all hard links appear as the original file or directory. Consequently, the hard links that you create point to the same storage location on your hard drive. So, if you make any changes to a hard link, the changes will reflect in the original file.
One thing to remember before using hard links is that you can’t create a hard link across different disk drives. So, if you have a file stored in the C: drive, your hard link must also be stored in the C: drive. This is a file system limitation.
Finally, if you have created a hard link for a specific file and you want to delete that file, you also need to delete every hard link. Since a hard link represents the actual file, they point to a storage location on your hard drive. So, to free the storage location, you have to delete every link that points towards it.
Soft Links work just like regular shortcuts. But they differ in one key way: symlinks represent the address of the file rather than the actual file. So, unlike a shortcut, a symlink is not a file. This is also why symlinks take up no space on your hard drive, and shortcuts do.
Contrary to hard links, symlinks don’t point to a storage location on the hard drive. They point to the file or the directory that points to the storage location. So, if you want to delete a file, you don’t have to delete all of the symlinks pointing to that file.
Symlinks can also be created across different drives because they point to the original file rather than the file’s storage location.
First, symlinks are faster than traditional shortcuts. Therefore, on a slow computer, you should use symlinks instead of shortcuts.
Second, there are situations when you have to copy/paste a large amount of data from one location to another. In such situations, it is preferable to create a symlink rather than copying and pasting. This can save a lot of storage owing to the lack of duplicate files.
Finally, some programs require you to have files present at a certain location on the storage drive. For instance, OneDrive only syncs files that are present in the OneDrive directory. By using a symlink, you can sync any file regardless of its location on your computer.
On Windows 10, you can set up symlinks through the Command Prompt using the mklink command.
First up, launch the Command Prompt by typing cmd in the Start menu search bar, then right-click the Best Match and select Run as administrator.
You can use the mklink command to create hard and soft links. To get an overview of the mklink utility, type mklink and press Enter. This will give you an overview of the mklink utility by listing the command syntax and the different options associated with it.
Now, let’s create a soft link to a text file using mklink.
Type mklink link target, replacing “link” with the address of the soft link that you want to create, and replace “target” with the address of the original file. The following image shows how to create a soft link named “softlink.txt” that references a file “original.txt.”
If you want to create a soft link to a folder or directory, use the format mklink /D link target. The “/D” option creates a symlink to a directory.
Creating a hard link also follows the same process. Use the same mklink link target command structure but with the “/H” option.
The following image shows how to create a hard link for the fictional “hardlink.txt” file, pointing to the same storage location as “original.txt.”
If you want to create a hard link to a folder or a directory, use the “/J” option instead of the “/H” option.
To get started, download Hard Link Shell Extension and install it. Make sure to pick the right package for your computer. For instance, if you have a 64-bit OS, download the 64-bit version. Unsure what you’re using? Here’s how to check whether you’re using 64-bit or 32-bit Windows.
After installing the package, navigate to the file or folder you want to create a link. Right-click on the file and select Pick Link Source from the dropdown list.
After picking the link, navigate to the destination folder where you want to create the link. Right-click on an empty area and select Drop Symbolic Link. This will create a symlink with the same name as the original file.
You can use the same method to create a hard link to a file or a folder. Remember that you can only create a hard link within the same disk drive. The Hard Link Shell Extension will only give you the option of creating a hard link if you are on the same disk drive.
After picking the link, right-click anywhere inside the drive, hover over Drop As, and select Hardlink. This will create a hard link to the original file.
Understandably, not everyone will find a use for symbolic links. But for people that like to keep everything tidy while using as little storage as possible, symbolic links are an awesome feature.
So, instead of copying files to different locations, create symbolic links, and you will be good to go.
Broken symbolic links can lead to performance problems in Linux. Here’s how to find and fix broken symlinks.
About The Author