In a previous article, I wrote about hard links as a way to instantly "copy" large files from one folder to another.
I put "copy" in scare quotes because with a hard link you are not actually making a copy of the file. Instead, you are just creating another file path that points to the original file.
Two file paths. One file.
Mimicking Client Environments
The subst command is a great way to mimic a client's network environment on your local development machine.
Assuming your client assigns drive letters to mapped network folders that store backend data files, you can use the subst command to assign the same letter to a local folder on your development machine.
For example, let's say Acme Co. has a T: drive mapped to a network folder that stores their backend database file,
AcmeBackend.accdb. If we had a copy of that file that we were using for debugging or development, we could place the file in our local computer in a folder named:
C:\temp\Acme_T_Drive\. We would then use the subst command to create a drive letter that pointed at this local folder:
C:\> subst t: "C:\temp\Acme_T_Drive"
The following two paths would point to the same folder:
Here's what it looks like in Windows File Explorer:
Managing Client Data Files in a Central Location
If you have lots of clients, you could end up with lots of
This would also mean you'd have a bunch of data files spread out everywhere. Let's say you wanted to keep track of all those files in a central folder, but still make the files available for mimicking client environments. You don't want to keep actual copies of the files, especially since backend data files can be so large.
This is where hard links come in.
Using the Link Shell Extension to Create Hard Links
By far, the easiest way to create hard links in Windows is to use the free Link Shell Extension.
Here's the step-by-step:
- Right-click the source file and choose "Pick Link Source"
- Right-click an empty area of the destination folder and choose "Drop As..." > "Hardlink"
Once we've created the hard link, we can open the Properties window for either file and go to the "Link Properties" tab to see a list of all the hard link references to the file:
Deleting the File
Here is where Windows starts treating the file sort of like a copy.
If I delete either file (using the normal Windows delete methods), it simply removes the reference to that file. The file is not removed from the disk until the reference count equals zero.
The "Link Properties" tab only appears for files with two or more links. Once I removed the copy of the
AcmeBackend.accdb file from the Recycle Bin, the "Link Properties" tab disappeared (after closing and reopening the Properties dialog).
The Mercurial version control system uses hard links when making local clones of repositories on Windows.
Here's a list of additional use cases as provided by ChatGPT:
[MIKE]: What are some example situations where Windows hard links would be useful?
[ChatGPT]: Windows hard links are a useful feature that allows multiple file system entries (or paths) to point to the same physical file on disk. Here are some example situations where Windows hard links can be beneficial:
File Versioning: Hard links are commonly used in backup or versioning systems. Instead of creating multiple copies of the same file, you can create hard links to the original file. This saves disk space while still maintaining multiple accessible versions of the file.
Shared Libraries: Hard links are used in Windows to create shared library files (DLLs). Different applications can use hard links to reference the same DLL, reducing disk space usage and ensuring consistency across applications.
Efficient File Synchronization: When synchronizing files between different locations or devices, hard links can be used to save time and storage space. Instead of copying identical files, you can create hard links at the destination, pointing to the original files. This allows for a faster synchronization process and reduces the amount of storage required.
Reducing Duplication: Hard links can be employed to eliminate duplicate files in a file system. Rather than having multiple copies of the same file scattered throughout the system, you can create hard links to a single copy. This approach helps to save disk space while maintaining accessibility from different locations.
File Organization: Hard links can be utilized to organize files more efficiently. For instance, you might want to categorize files in multiple directories without duplicating them. By creating hard links in different directories, you can organize files while still having them stored only once.
Efficient Software Packaging: Hard links are valuable in software packaging scenarios. When creating installation packages or deploying software, hard links can be used to link files into different directories without duplicating the actual file data. This allows for a more streamlined installation process and reduces the storage footprint.
These are just a few examples of situations where Windows hard links can be beneficial. The flexibility of hard links provides numerous possibilities for optimizing disk space usage, file organization, and file management in various contexts.