Symbolic Links are also known as Symlinks. Symlinks are used to create a shortcut for a given file or folder. Symlinks are very useful for different purposes which also prevents copy the same data over and over again. In this tutorial, we will learn what is symlinks and how to create and use symlinks for Linux and Windows operating systems?
There is two type of symlinks. These are called Soft and Hard. Generally, Symlink is used for Soft symbolic links which are more popular than hard links.
Soft links are just links they do not contain actual data. Soft symlinks can be used to point different partitions.
Hardlinks are used to point directly to the actual data. Hard links can not be used to point to different partitions.
Create Symlink For Windows
Windows operating systems provide
mklink command to create the soft and hard symlink. If we want to create symlinks for paths like
C:\ we generally need Administrator privileges because of these paths is a special path for users.
Create Soft Symlink For File
We can create a soft symbolic link for a file just providing the file name and symbolic link name like below. We will create a link named
> mklink test.bat autoexec.bat
Create Soft Symlink For Directory/Folder
In order to create Hard Symlink for a file we will use
/D option like below. We will also provide source and link name.
> mklink /D test.bat autoexec.bat
Create Hard Symlink For File
We can create a hard symlink for a file with the
/H options like below.
> mklink /H test.bat autoexec.bat
Create Hard Symlink For Directory/Folder
In order to create a hard symlink for a directory or a folder, we will provide the
/J option like below.
> mklink /J test.bat autoexec.bat
Create Symlink For Linux
Linux distributions like Ubuntu, Debian, Mint, Kali, Fedora, RedHat, CentOS provides the
ln command in order to create symlinks.
ln command can detect the file or folder and create symlink automatically. We will just provide soft or hard link option.
Create Soft Symlink
We will use
ln command in order to create a soft link for a file or directory. We will provide the
-s option which means create a soft link, not a hard link.
$ ln -s /home/ismail/run.sh /mnt/run.sh
Create Hard Symlink
We can create hard symlinks with the
ln command too. We will just provide the source file name and the link name like below.
$ ln /home/ismail/run.sh /mnt/run.sh