Intro to symbolic links
March 16, 2023
Bellevue, WA
Symbolic links otherwise known as Symlinks, are pointers that act or replicate the presence of the file it is pointing to. For example you want to have a file show up in a second location without actually having to copy and paste the desired file into that secondary location you could use a symlink.
You can use symlinks not only with indvidual files, but also with entire directories (and even point at another symlinks). A good use for symlinks is for configuration files that need to be set the same way in many different folders/directories. You would just set up a symlink to point at the configuration file from the original directory in the secondary directory.
There are 2 types of symlinks, a "hard" symlink and a "soft" symlink. A soft symlink is similar to a shortcut, it would be in the folder and when you want to access it, you would be redirected to the actual location of the file. A hard symlink would be more than just a redirect, it would work as if the file was in secondary directory.
Here's how you could set up symlinks in Windows
In Windows you can access the built in tools to create symlinks within Powershell
C:/Users/user>mklink
This will prompt you to choose from 3 options:
MKLINK [[/D] | [/H] | [/J]] Link Target
/D makes a Directory link (soft, can be file or directory)
/J makes a Junction link (hard, but directory only, not direct on file)
/H makes a Hard link (can only be a local file not directory) does not take up real drive space
You could enter in something like this..
mklink /D "C:\PS\Downloads" "C:\Users\user\Downloads"
This would create a Directory link, that would exist in the directory PS\Downloads, and would point at user\Downloads
NOTE: In order to create symlinks in Windows you must have admin access. Otherwise you will get an error that tells you "ou do not have sufficient privilege to perform this operation"
References
- The Complete Guide to Creating Symbolic Links (aka Symlinks) on Windows
- Symlinks by Antora
- Creating Symbolic Links (Symlinks) in Windows