Open In App

Difference between Relative and Absolute symlinks

Improve
Improve
Like Article
Like
Save
Share
Report

Symbolic Link (aka symlink) is a file that doesn’t store any data, but rather reference to another file or directory in the form of absolute or relative path. Strictly speaking, A symbolic link isn’t necessarily a file, but it is rather file system object. A symlink doesn’t occupy any space (0 bytes of space occupied), but rather exists as special entry in file table. Symbolic link for many operations will behave as if operating directly on target file. During creation of Symbolic links, type is associated with final symbolic link, which is used to access the target. Symbolic link can be of two types Relative or Absolute. In this article we will learn what are differences between these two types of symbolic links, and would also learn to create them.

Types of Symbolic Links :
There are two types of symbolic links : Absolute symbolic links, and Relative symbolic links. These are explained as following below.

1. Relative Symbolic Link :
An relative symbolic link is an symbolic link, whose target has relative path. An relative path is path that is based on Current Working Directory. The path of target file/folder will be calculated according to the current path of symlink. Therefore, there is no definite path so as to say. As the path is always computed accordingly to current location of symlink. For example, let’s assume a symbolic link (file) has following target path.

..\Apples

Symbolic link described above is relative symbolic link. The reason is because it has the .. (double period) in its path which is for denoting parent of directory in which filer currently resides. This makes is dynamic as file could be anywhere, but it will look for target file in a file named apples in its parent directory. Therefore, target path becomes depended on path of file.

It should be noted that double period ( .. ) is not literal TWO periods in succession, but rather directory operand referencing parent directory.

Creating Relative Symbolic Links :
For creating a relative symbolic link on windows, we would be using mklink command. Syntax for creating relative symbolic link is as follows :

mklink new_Link_name Target_path

And the target path should be relative. In the following example we will be creating a file symbolic link named Floss having its target file (named test.jpg) inside one of the subdirectory (named Bin) of its parent directory.

Example :

In order to create symbolic links on windows, command prompt (cmd) must be executed with elevated privilege’s

2. Absolute Symbolic Links :
An absolute symbolic link is symbolic link, whose target is absolute/full path. An absolute path is path that exists on its own and has no dependency on Current Working Directory. The path of target file/folder will always be the same, regardless of location of symlink. For example, let’s assume symbolic link (file) has following target path.

C:\Program Files\Windows\Leon.txt

Symbolic link described above is an absolute symbolic link. Reason is because it contains hardcoded Target path. Due to which regardless of location of symbolic link, lookup for the target file would be for only one path.

Creating absolute Symbolic Link :
For creating a absolute symbolic link on windows, we would be using mklink command. Syntax for creating relative symbolic link is as follows :

mklink new_Link_name full_Target_path

The full_target_path should be full path (including drive specifier) to target file. In the following example we will be creating a file symbolic link named Lesson.txt having a the target file at location C:\Users\French\Workshop.txt

Example :

NOTE :
It should be noted that the type of symbolic link (relative/absolute) does not depend on way source path (New_Link_Path) was provided. Therefore new link path could be provided relative or absolute according to preference, as it would have no impact in the type of symbolic link. It’s the Target path which is determinant of the type.


Last Updated : 09 Oct, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads