Overview
Symbolic links are commonly used in various operating systems, including Unix-like systems such as Linux and macOS, as well as Windows, to create flexible and dynamic file structures, facilitate file organization, and simplify administration tasks. They are frequently employed for creating shortcuts to files or directories, creating virtual copies of files, and providing access to files or directories located in different parts of the file system.
In short, by using symbolic links, we can easily redirect one folder or files to another location.
The built-in tool to manage or create a mklink in windows called a mklink
that can be running over Command Prompt (CMD)
, but in this article, I’ll only show you to create and manage them over the Powershell
.
Symbolic Link Type
The following are the threee types of the link supported in NTFS
file system, and how to use it.
Symbolic Link (symlink)
This type of symbolic link, also known as a soft link
is basically an advanced shortcuts. You can create a symbolic link to a local
or remote file
, folder
, or shares path
, and that link will appear to be the same as the target source. When you open a symbolic link, you will be redirected to the target source
- Symbolic links do support UNC paths (
network paths that begin with \\
).- Symbolic links will have
a shortcut arrow icon on them
.- Symbolic Link that redirected to a file is called as:
SYMLINK
- Symbolic Link that redirected to a directory is called as:
SYMLINKD
To Create Symbolic Link (symlink):
New-Item -ItemType SymbolicLink -Path "Link" -Target "Target"
Junctions (Directory Junction)
Junctions (Directory Junction) are soft links that can only be created to a local folder (directory) path. Junction points make it appear as though folder (directory) actually exists at the location of the junction point, and your app won’t know any better.
- Junction points
do not support UNC paths (network paths that begin with \\)
.- Junction points will have
a shortcut arrow icon on them
.- Deleting anything inside the link/junction or target (source) folder will delete it in both folders.
- Deleting the hard link, symbolic link, or junction point itself will not delete anything in the target (source) folder.
To create Junctions (Directory Junction):
New-Item -ItemType Junction -Path "Link" -Target "Target"
Hard Links
Hard Links can only be created for files. Any changes to that file are instantly visible to applications that access it through the hard links that reference it.
- Hard links do not support UNC paths
(network paths that begin with \\)
.- Hard links to a file will not have
a shortcut arrow icon on them
.
To create Hard Links:
New-Item -ItemType HardLink -Path "Link" -Target "Target"
Determine or Find All Symbolic Links and Junction Points.
To determine a listed folder is containing a standard file or symlink, you can use the following:
In CMD
In CMD
you can use the following to see the files/folders Type
:
DIR /AL /S
Output:
02/21/2022 05:35 AM <DIR> Documents
10/24/2023 07:09 AM DailyNotes.txt
04/07/22022 01:00 PM <JUNCTION> DailyBackup [\??\F:\BACKUP\]
10/25/2022 10:29 AM <SYMLINK> Syshealth.ps1 [F:\HomeAutomation\Syshealth.ps1]
02/25/2024 07:48 AM <SYMLINKD> WWW [\\websvr01.amanulloh.com\www]
As you can see, there are some different Type
of files/folder on that output.
DIR
= Standard folder (Directory)EMTPY
= Standar files (doesn’t have anyType
)JUNCTION
= Junction point to folder (directory)SYMLINK
= Symbolic link to fileSYMLINKD
= Symbolic link to folder (directory)
In Powershell
In Powershell
you can use ls
to show all files and directories
, and see the mode
- Directory (D): The entry is a subdirectory, containing file and directory entries of its own.
- Reparse Point (L): The file or directory has an associated re-parse point, or is a symbolic link.
To check further the Mode
or Attribute
use the following:
gci|select mode,attributes -u
Output:
Mode Attributes
---- ----------
d---- Directory
d---- Directory, NotContentIndexed
d-r-- ReadOnly, Directory
l---- Directory, ReparsePoint
-a--- Archive
la--- Archive, ReparsePoint
And you can use this command and these attributes
to find a Standard DIR
, or JUNCTION
, SYMLINK
, SYMLINKD
:
-a---
= Standard filed-r--
= Junction point to folder (directory)la---
= Symbolic link to filel----
= Symbolic link to folder (directory)
This is example to find only the SYMLINK
to a file.
ls | where {$_.Mode -eq "la---"}