Good day techies!!!
Softlink and Hardlink. This is essential to know about links (both softlink or Symlink and hardlink) because we are Linux techies.. It’s vital to knowing about how Linux/Unix environment works!! Here I’m explaining both Soft and Hard links with appropriate examples.
Both soft link and hard link are used to make links between files/directories.
I’m pretty sure about the examples I explain here will be much helpful for you to know this concept in detail 🙂 This will definitely give a clear idea on Linux links.
What is Soft link(symbolic link/symlink)?

This is very similar to what we know about the Shortcuts option available in Windows. It contains the information about the destination file. Symbolic link points the link to the file or directory name.
This is the main difference between both links. As the soft link is pointing to the file or directory name, the link will not be accessible if the original file or folder is deleted/removed.
More details are added under the deference b/w section.
What is hard link?
It’s a bit difference object as compared to Softlink. Hard link is the reference or pointer to the exact file. That’s why we can access if the original file is removed or moved from the original location.
Hard link is a label stored in a directory structure that refers the OS to the file data when it is accessed.
The important part is the hard link is more close or related to the original file.
Softlink and Hardlink. Differences between symbolic link or soft link and hard link
Quick view table
Soft link | Hard link |
---|---|
ln -s | ln |
Can create soft link for both files and directories. | Files only. |
Symbolic link points the link to the file or directory name. | Hard link is the reference or pointer to the exact file. |
The link will not be accessible if the original file or folder is deleted/removed. | Can access. |
Different inode value. | Same inode number. |
Soft link is possible in different partition. | Not possible. |
Something more about Soft and Hard links
Hardlink
1, The ‘ln’ command by default create hard links.
Syntax:
# ln $Sourcefile $Link
Example:
[[email protected] home]# touch crybit
[[email protected] home]# echo "Hardlink test" > crybit
[[email protected] home]# cat crybit
Hardlink test
Create a hardlink of this file to a file in your / location:
[[email protected] ~]# ln /home/crybit link
[[email protected] ~]# cat link
Hardlink test
2, Hard link not allowed for directory:
Proof:
Create a test diretory under /home location:
[[email protected] home]# mkdir hard
Try to link that directory:
[[email protected] ~]# ln /home/hard/ link
ln: `/home/hard/': hard link not allowed for directory
3, Original file and linked will have the same inode number:
Proof:
You can find out the inode value by using the ‘ls’ command with ‘-i’ switch:
# ls -li $file
[[email protected] ~]# ls -li /home/crybit
147144 -rw-r--r--. 2 root root 0 Jan 31 04:48 /home/crybit
[[email protected] ~]# ls -li link
147144 -rw-r--r--. 2 root root 0 Jan 31 04:48 link
In the above example the inode value is "147144".
4, We can access if the original file is removed/moved from server.
Proof:
Remove the original file:
[[email protected] home]# cat crybit
Hardlink test
[[email protected] home]# rm -rf crybit
Access the link file:
[[email protected] home]# cd
[[email protected] ~]# cat link
Hardlink test
5, Pointing link to the data location, that’s why we can access if the original file is removed from the location.
6, Hard link is not possible in different partition.
Proof:
1, Create a test file in one partition:
[[email protected] boot]# touch test
2, try to link from another location(Partition):
[[email protected] boot]# cd
[[email protected] ~]# ln /boot/test link
ln: creating hard link `link' => `/boot/test': Invalid cross-device link
Softlink
1, The ‘ln’ command with switch ‘s’ is used to create the softlink
Syntax:
# ln -s $Sourcefile $Link
[[email protected] ~]# cd /home/
[[email protected] home]# touch crybit
[[email protected] home]# echo "Softlink test" > crybit
Create softlink from another location:
[[email protected] home]# cd
[[email protected] ~]# ln -s /home/crybit link
[[email protected] ~]# ll link
lrwxrwxrwx. 1 root root 12 Jan 31 13:10 link -> /home/crybit
[[email protected] ~]# cat link
Softlink test
2, We can softlink directory also
Proof:
Create a test directory in /home location:
[[email protected] home]# mkdir test
Create a soft link to /home/test directory from another location:
[[email protected] ~]# ln -s /home/test/ linkdir
------
lrwxrwxrwx. 1 root root 11 Jan 31 13:15 linkdir -> /home/test/
------
3, Original file/directory and the linked file/directory are having different inode value.
Proof:
[[email protected] home]# ll -i crybit
147144 -rw-r--r--. 1 root root 14 Jan 31 13:10 crybit
[[email protected] home]# cd
-----
[[email protected] ~]# ll -i link
525994 lrwxrwxrwx. 1 root root 12 Jan 31 13:10 link -> /home/crybit
4, We can’t access, if the original file/diris removed/moved from server.
Proof:
[[email protected] home]# rm -rf crybit
[[email protected] home]# cd
[[email protected] ~]# cat link
cat: link: No such file or directory
5, Pointing link to the file/dir name, so we can’t access if the original file/dir is removed from the location.
6, Soft link is possible in different partition.
Proof:
[[email protected] ~]# cd /boot/
[[email protected] boot]# mkdir test
[[email protected] boot]# cd
[[email protected] ~]# ln -s /boot/test/ linkdir
[[email protected] ~]# ll -d linkdir
lrwxrwxrwx. 1 root root 11 Jan 31 13:31 linkdir -> /boot/test/
These are the common difference between Softlink and Hardlink..! Happy linking 🙂
What is a Linux container?
Basic: Containerisation helps to isolate processes. You can run your App/Services as an isolated process, running from a distinct image that provides all files necessary to support the processes.
Basically Linux containers are OS level virtualisation technique for running multiple isolated Linux systems (containers) on a control host using a single Linux kernel.
More:
groupdel, groupmems, groupmod, useradd , usermod , chgrp, chown, ls, head, tail, top, ps, find, crontab
Tq it is good to understand
You are most welcome, Ankitha!
Really it’s nice article Ashok.
Thanks Sameer 🙂
HI Ashok,
can you help in how to change permissions of lrwxrwxrwx 1 root : root rmd.log -> /opt/IBM/HTTPServerV8.5/htdocs/logs/RMDLogs/rmd.log
if i want to have permisions as 770 instead of 777..can i know how to change?? as with chmod the permisions are not changing
thank you
Hi Ramana,
Chmod, that’s the option. Actually the link file is just a shortcut to the real file. It has the same permission, even it’s showing 777. Try chmod on a link and check the permission of real file.
See the example pasted below: