Junction vs Symbolic Links - Windows


👤 Diwas Poudel    🕒 09 Oct 2022    📁 TECH

Microsoft introduced linking commands in the NTFS-based Operating systems after Windows NT 4.0 and Windows 2000. As a result, the MS-DOS operating system did not support any links. These Links show the relationship between different entities by seamlessly pointing and redirecting one entity and its content to another entity with no special handling needed. You can think links are like pointers pointing to files or directories.

These linking commands in the Windows OS include HardLinks, Symbolic Links, and Junction Links. These links are extremely useful; they allow you to avoid having multiple copies of the same file while still accessing the same file content from different folders with different names.

Links can be created in Linux and Unix operating systems, but this article will discuss the differences between symbolic links and junction links in Windows OS. When newcomers first learned about links, they were puzzled by these commands. Don't worry, ourtechroom will assist you.

Let's look first at Junction Links:

Junction Links

With the introduction of Links tools in the Windows Operating System, Junction Links was introduced. As a result, it is only compatible with Windows 2000 and later. It appears to be Windows OS legacy links. Junction Links uses an implementation of an NTFS feature called reparse points to perform links.

Junction Links is a link tool that allows you to create a link to a folder/directory only on the same or different local volume (drive letter) on the same computer or indifferent
external hard drive. So your folders located in one location can be accessed from multiple partitions or volumes in your hard drive.

Keep the following points in mind when working with Junction.

  • For Junction Links, we have to use the Absolute path for defining the target path. No relative path works in Junction Links.
  • Junction Links does not work with files. But only for directory/folder.
  • Junction Links only works for the local directory but not for a remote directory.
  • You don't need any admin rights to create Junction links between directories.
  • The original directory is not affected when junction link points are removed or deleted.
  • When the target / original directory is removed, deleted, or moved, the junction point remains but continues to point to the non-existent original directory.

Warning! Do not create junctions pointing to folders on removable drives such as USB pen drives and SD cards, and do so as soon as possible for system-critical folders; otherwise, applications may stop working or Windows may not even start.

With the help of Junction we can do as follows:

  • C:\DirA linked to C:\DirB
  • C:\DirA linked to C:\DirB\DirC
  • C:\DirA linked to D:\DirD

With the help of Junction links we cannot do the following and give you an error:

  • C:\DirA\target.txt linked to C:\DirB\link.txt
  • C:\DirA linked to Z:\DirZ
Also Read: Run multiple commands in one line in Powershell and Cmd

We can use the mlink command to create Junction links as follow:

mklink /J "D:\Target Folder" "C:\My Web Sites"

In this example, we are relocating the folder "C:\My Web Sites" to "D:\Target Folder." When anything software or users tries to access directories within "C:\My Web Sites" Windows will redirect the user and grab the files from "D:\Target Folder" instead. As a result, the space on your C drive is unused and free, and it can be used for something else.

But if you already have the Target Folder name in D drive then you cannot create Links and will get an error message like "Cannot" create a file when that file already exists" as shown below.

junction-already-exists

So, the target folder must be different. So, we have selected the folder name "New Target Folder" in the D drive and this folder is not reserved in the D partition. So, let's run the command below:

mklink /J "D:\New Target Folder" "C:\My Web Sites"
junction-created
fig. Junction Created Successfully

Then junction is created as shown below in Windows Explorer. It will have small shortcut icons in Junction Folder Link.

target-folder-shortcut

Here, we can see the junction folder as <Junction>, and these links take up no space.

showing-junction-doesnot-occupy-space.

Symbolic Links

Symbolic Links is compatible with Windows Vista (Desktop Environment), Windows Server 2008 (Server Environment), and subsequent Windows operating systems. It is more sophisticated than Junction Links.

Symbolic Links are advanced Link tools and commands that allow you to create a link to a folder/file on your local computer or a remote computer (using SMB paths to point at targets across a network). However, keep in mind that any local or network computer that uses Symbolic Links must be running Windows Vista, Windows Server 2008, or later. Symbolic Links work for both relative path and absolute path.

With the help of Symbolic Links you can do as follows:

  • C:\DirA linked to C:\DirB
  • C:\DirA linked to C:\DirB\DirC
  • C:\DirA linked to D:\DirD
  • C:\DirA linked to \\server\shared\foldername\ or mapped drive Z:\
  • C:\DirA\target.txt to D:\link.txt
  • C:\mountain.png to D:\himalayas.png
Also Read: How to sleep or wait in Windows batch file?

With the help of Symbolic links we cannot do the following and give you an error:

  • \\NETWORK\SHARE linked to a local folder like C:\DirA.  

ie. Users cannot access that network symlinks.

When I make a symbolic link, I make a file/folder with a path to another file/folder ( which might be another symbolic link as well). Symbolic Links are simply the name of another file, symbolic links can span different supported file systems. As a result, symbolic links can exist across filesystems.

Microsoft introduced Symbolic Links to be more compatible with Unix. From Microsoft Official Site: "Symbolic links are designed to aid in migration and application compatibility with UNIX operating systems. Microsoft has implemented symbolic links to function just like UNIX links."

We can use the mlink command to create Junction links for the folder as follow:

mklink /D "C:\Program Files\Software" "D:\My Software"

In this example, we are relocating the folder "C:\Program FilesSoftware" to "D:\MySoftware." When anything software or user tries to access directories within "C:\Program FilesSoftware," Windows will redirect the user and grab the files from "D:\MySoftware" instead. As a result, the space on your C drive is unused and free, and it can be used for something else. 

So, if you change the content in Symbolic links(D:\MySoftware) will auto changes in the target folder ie. Software.

Also Read: How to view the list of active remote desktop Users in Windows Server

Junction Links vs Symbolic Links

Junction Links and Symbolic Links seem to have similar features. But there are some noticeable differences and they are as follows:

Junction Links Symbolic Links
Introduced in Windows 2000 OS and compatible to Windows with Windows 2000 and beyond. Introduced with Windows Vista and Windows Server 2008. So, compatible with Windows those OS and beyond.
Junction Links works only for directories. Symbolic Links work for both directories and files.
Junctions links work only for the absolute path. Symbolic Links works for both absolute and relative path.
Junction Links work for the local drives volumes and partition only Symbolic Links works for local as well as remote drives.
Creating junction links does not require any special permissions, and Windows Standard User is sufficient. As a result, we can say it has a low-security profile. Creating Symbolic Links requires Administrator privileges. Therefore it has high-security profiles.
It is a legacy Links type created for the NTFS file system. It is modern links types and was developed to support migration and application compatibility with UNIX operating systems.
To Delete the Junction link you can use the RD command. To Delete the Symbolic link you can use RD or del command.
Junction Links is supported on Windows 2000 and above. Symbolic Links is supported on Windows Vista and above.

How to know symbolic Links is created?

Right-click on symbolically linked folders/files and select Properties; this displays the shortcut properties of the currently selected files.

How to know Junction Link is created?

Right-click on files created by junction links and select Properties; this displays the original directory folder properties.

Conclusion:

Junction Links and Symbolic Links are useful tools for creating links between folders/files.