How to Create Linux Symbolic Link ( Soft Link/ Hard Link)

How to Create Linux Symbolic Link in Linux/Unix

Understanding shortcuts or links is a piece of cake.
Most of us have already did that on Windows. Some of us have even tried
creating on Linux symbolic link. A link in Linux is presented with an arrow -> that points
to the target or original file. A link is nothing more than a way of matching
two or more file names to the same set of files data.

linux symbolic link

There are two types of links available in Linux –
 
  1.  Soft Link
  2.  Hard Link

 

Soft
Link
Hard
Link
1
Size
of link file is equal to no. of characters in the name of original file
Size
of both file is same
2
Can
be created across the Partition
Can’t
be created across the partitions
3
Inode
no. of source and link file is different.
Inode
No. of both file is same
4
If
original file is deleted, link is broken and data is lost
If
original file is deleted then also link will contain data.
5
Shortcut
File
Backup
File
In Linux ln
command is used to create either soft or hard links.
This article explains how to create soft link, how
to create hard link:
Creating a Soft Link:
 
Symbolic links are simple to create. The syntax for
creating a Linux symbolic link from command line is:
Create a Soft link for a File
 
The following examples shows a Soft link.
#
ln –s <source file> <destination file name>
 
[root@rahul
~]# ln -s file1 file1.softli
[root@rahul
~]# ls -li file1 file1.softli
9466
-rw-r–r–. 1 root root 76 Aug 24 17:51 file1
9502
lrwxrwxrwx. 1 root root  5 Sep 15 20:38
file1.softli -> file1
[root@rahul
~]#
Create a Soft link for a Directory
 
Just like file, you can create Soft link for
directories as shown below.
#
ln –s <source dir> <destination dir name>
 
[root@rahul ~]# ln -s /home/rahul/dir directory
[root@rahul ~]# ls -l directory
lrwxrwxrwx
1 rahul rahul       6 2016-09-15 16:48 directory ->
/home/rahul/dir
Creating
a Hard Link:
 
The inode number for the hard linked files would be
same. The hard link for files can be created as follows:
#
ln <source file > <destination file name>
 
[root@rahul
~]# ln file1 file1.hardli
[root@rahul
~]# ls -li file1 file1.hardli
9466
-rw-r–r–. 2 root root 76 Aug 24 17:51 file1
9466
-rw-r–r–. 2 root root 76 Aug 24 17:51 file1.hardli
[root@rahul
~]#
 
If you like Articles then like, comment and Share…
 
 

 

Leave a Reply

Your email address will not be published. Required fields are marked *