Operating System - HP-UX
1828977 Members
2091 Online
109986 Solutions
New Discussion

Difference between soft and hard links

 
SOLVED
Go to solution
Sathyaswarupa
Contributor

Difference between soft and hard links

what is the use of a hard link and a soft link?
8 REPLIES 8
Arunvijai_4
Honored Contributor

Re: Difference between soft and hard links

Hello,

Here is a very good resource about the differences between hard and soft links,

http://linuxgazette.net/105/pitcher.html

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Joseph Loo
Honored Contributor

Re: Difference between soft and hard links

hi,

"man ln" for more info.

refer to this discussion as well:

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=605109

regards.
(p.s. please remember to assign points.)
what you do not see does not mean you should not believe
Ivan Ferreira
Honored Contributor

Re: Difference between soft and hard links

Normally, soft links are used. Hard links and soft links have differents properties, but soft links are more common.

The most important.-

Soft links:

They are different files (different inodes).
- If you delete the link, the original file is intact
- If you delete the original file, the link will reference to an unexistant file.

They can transverse file systems.

Hard links:

They are the same file (same inode).
- If you delete any of the files, the remaining file will still point to the data.

They can be created only on the same file system that the file that references.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Sivakumar TS
Honored Contributor

Re: Difference between soft and hard links


Dear Sathya,


1. The Soft links are different files having different inodes. You can check this by

#ls -li

note the INODE number of the files.

The link(ed) file's content will be have the PATH to the original file. So even if you delete the link, the original file is intact.

2. Hard links are the same file, which has the the same inode( check it with #ls -li).


And one more difference is,


softlink ---> can be made across the filesystems

Hardlink ---> can be made ONLY within a filesystem

With Regards,

Siva.
Nothing is Impossible !
Rory R Hammond
Trusted Contributor

Re: Difference between soft and hard links


A hard link is basically duplicate entry on the same filesystem. Generally files have one name associated with a inode entry. A hard link is a directory entry with ANOTHER NAME associated with the same inode entry. With a hard link you directly go to the INODE to read/write/execute a file.

make a link do an ls -li on both names and you will find they have same inode entry.

A soft link is also called a symoblic link. A symbolic link points to the real file name location. Since the entry is a pointer, It can point to entries on any filesystem. When accessing a file via a soft link, the system sends you to the real file name, which then directs you to the INODE location to read/write/execute a file.

Rory
There are a 100 ways to do things and 97 of them are right
Sathyaswarupa
Contributor

Re: Difference between soft and hard links

But Gurus, Why do we need both hard and soft links?
Can any one of you explain it with the help of a real example which really makes use of this distinction in hard and soft links?
Arunvijai_4
Honored Contributor

Re: Difference between soft and hard links

http://forums1.itrc.hp.com/service/forums/helptips.do?#28

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Rory R Hammond
Trusted Contributor
Solution

Re: Difference between soft and hard links


You can not link a directory to a another using a hard link
you can link a directory with a soft link.

Traditionally hard

On my system /usr/sbin has the following hardlinks associated with inod 22596
ls -li |grep 22596
22596 -r-sr-xr-x 31 root sys 557056 Nov 14 2000 lvchange
22596 -r-sr-xr-x 31 root sys 557056 Nov 14 2000 lvcreate
22596 -r-sr-xr-x 31 root sys 557056 Nov 14 2000 lvdisplay
22596 -r-sr-xr-x 31 root sys 557056 Nov 14 2000 lvextend
22596 -r-sr-xr-x 31 root sys 557056 Nov 14 2000 lvlnboot
22596 -r-sr-xr-x 31 root sys 557056 Nov 14 2000 lvmerge
22596 -r-sr-xr-x 31 root sys 557056 Nov 14 2000 lvreduce
22596 -r-sr-xr-x 31 root sys 557056 Nov 14 2000 lvremove
22596 -r-sr-xr-x 31 root sys 557056 Nov 14 2000 lvrmboot
22596 -r-sr-xr-x 31 root sys 557056 Nov 14 2000 lvsplit
22596 -r-sr-xr-x 31 root sys 557056 Nov 14 2000 lvsync
22596 -r-sr-xr-x 31 root sys 557056 Nov 14 2000 nomwcsyncd
22596 -r-sr-xr-x 31 root sys 557056 Nov 14 2000 pvchange
22596 -r-sr-xr-x 31 root sys 557056 Nov 14 2000 pvck
22596 -r-sr-xr-x 31 root sys 557056 Nov 14 2000 pvcreate
22596 -r-sr-xr-x 31 root sys 557056 Nov 14 2000 pvdisplay
22596 -r-sr-xr-x 31 root sys 557056 Nov 14 2000 pvmove
22596 -r-sr-xr-x 31 root sys 557056 Nov 14 2000 pvremove
22596 -r-sr-xr-x 31 root sys 557056 Nov 14 2000 vgcfgbackup
22596 -r-sr-xr-x 31 root sys 557056 Nov 14 2000 vgcfgrestore
22596 -r-sr-xr-x 31 root sys 557056 Nov 14 2000 vgchange
22596 -r-sr-xr-x 31 root sys 557056 Nov 14 2000 vgchgid
22596 -r-sr-xr-x 31 root sys 557056 Nov 14 2000 vgcreate
22596 -r-sr-xr-x 31 root sys 557056 Nov 14 2000 vgdisplay
22596 -r-sr-xr-x 31 root sys 557056 Nov 14 2000 vgexport
22596 -r-sr-xr-x 31 root sys 557056 Nov 14 2000 vgextend
22596 -r-sr-xr-x 31 root sys 557056 Nov 14 2000 vgimport
22596 -r-sr-xr-x 31 root sys 557056 Nov 14 2000 vgreduce
22596 -r-sr-xr-x 31 root sys 557056 Nov 14 2000 vgremove

Note that this is the same executable with a different name. This arangement save physical space, because there are not 31 seperate copies of the same same file, but 1 copy with 31 entries. this save space and reduces the type and number of options you need to invoke the using the same name. Traditionally hard links let you put the same file name in different directories, the above example is more common.

ls -ld /opt/java*
lrwxr-xr-x 1 root sys 12 Nov 16 12:26 /opt/java -> /opt/java1.3
lrwxr-xr-x 1 root sys 16
dr-xr-xr-x 4 bin bin 96 Mar 9 2004 /opt/java1.2
dr-xr-xr-x 3 bin bin 96 Mar 9 2004 /opt/java1.3
dr-xr-xr-x 3 bin bin 96 Mar 10 2004 /opt/java1.4

On one of my systems I have 3 version of Java
java1.2, java1.3 java1.4.

We have application that requires java1.3
The applaciation path points to /opt/java which is a soft link to /opt/java1.3.
When the application is upgraded and needs java1.4, I will not have to install java1.4, I only have to change the /opt/java soft link to point ot /opt/java1.4

Hope this helps
rory
There are a 100 ways to do things and 97 of them are right