May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

Categories

May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

Soft Link and Hard Link in Linux

Linux provides the user’s to save the same data of a file with one or more different names in different places of a same partition in two ways :

  1. Hard Link
  2. Symbolic Link
Hard link is  a directory entry which is associated with a file on a file system  The term is used to represent multiple links to a single file on a file system. lets say we have created two different files with same data and opened one of the file and made some changes to the files, we can see the changes applied to the file when the other file is opened.
Hard links can only be created to files on the same volume. If a link to a file on a different volume is needed, it may be created with a symbolic link.
How to Create Hard Link in Linux ..?
Use the following syntax to create a hard link between two files on the same file system.
ln {source} {link}
Where ,

  • Source is an existing file.
  • link is the file to create(a hard link).
To create a hard link for a foo file, follow the below commands.
echo ‘This is a test file for Hard Link’ > foo.txt
ln foo bar
ll -li bar fooHere is how output looks like …..[root@localhost prem]# ls -li bar.txt foo.txt
152667 -rw-r–r– 2 root root 34 May 18 21:07 bar.txt
152667 -rw-r–r– 2 root root 34 May 18 21:07 foo.txt

Symbolic Link is also known as symlink & soft link is a special type of file which contains the reference of other file, just like a pointer which stores the values to which it points. Similarly symbolic link stores the reference of other files, so as if any changes are ,made on one file then automatically the link which stores the reference of other file will automatically gets updated. Symlink is major used when two files are on different partitions in Linux.
How to Create Symlink or Soft Link in Linux ..?
Use the below syntax to create soft link:
ln -s {target filename} {symbolic file name}
 -s option for soft link
For example :
ln -s /home/httpd/index.html /home/prem/fwss.html
ls -l
Here is the sample output.
 lrwzrwxrwx 1 prem prem16 2013-05-16 10:13 index.html >/home/prem/fwss.html

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>