Hard Link? Soft Link ?

What is hard link and soft link? and what's the differences between them?
totoro030898Asked:
Who is Participating?
 
kokopeliCommented:
Totoro,
Given the nature of your question, it might be helpful for you to have a little background on how files are accessed and organized by the UNIX system...
When you use a UNIX system, it stores your files on a disk that is segmented into one or more partitions, or slices.  Each of these partitions can have a distinct filesystem placed on it.  When a filesystem is created, objects called "inodes" are created.  Inodes store the location of an individual file and it's characteristics such as owner and permissions.  Whenever you ask to read or write a file the kernel will always resolve the filename that you provide into the associated inode number and then find the file using that number.

So, anyways, on to your link question...  When you create a soft (symbolic) link "ln -s" you are creating a new file with it's own new inode that just points to the name of the file you want.
However, when you create a hard link, you are actually just creating another file instance of the orignal file, both will have the same inode number (you can see inode numbers by doing an ls -i).  Once you create a hard link, there is no way to tell the original file from the hard link.  This leads to an interesting restriction, you cannot create a hard link which crosses filesystem boundaries/partitions.  The reason for this goes back to the fact that inodes are allocated for each filesystem, and are not managed by any central process.  Thus, you can have a file in one partition with the inode #100 and a completely different file in another partitions with inode #100....  so doing hard links across partitions would really screw things up.

- kokopeli
0
 
ozoCommented:
Hard links point to the same inode
A soft or symbolic link is a special kind of file whose contents are the name of another file
0
 
ahoffmannCommented:
in addition to ozo's comment:

because of a hard link's nature (inode), hard links cannot cross partitions (usually),
while a symbolik link may point to a file/directory (or whatever is possible in a file system) anywhere, even on NFS

removing a hard links does not remove a file as long as it is not the last link count (no more hard links), removing the target of a symbolic link makes the file inaccesable
0
 
yonatCommented:
Soft links are like "shortcuts" in MS Windows and "aliases" in Mac. A hard link is the same, only the is no one link is the "original" file - they are all equal (except for their paths).
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.