Solved

Hard Link? Soft Link ?

Posted on 1998-09-13
4
1,818 Views
Last Modified: 2013-12-26
What is hard link and soft link? and what's the differences between them?
0
Comment
Question by:totoro030898
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1293193
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1293194
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
 
LVL 5

Expert Comment

by:yonat
ID: 1293195
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
 

Accepted Solution

by:
kokopeli earned 50 total points
ID: 1293196
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

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Perl Awk Need Help 3 129
post4 challenge 28 104
canBalance challenge 34 98
Trying to run powershell  in a batch file. How do I do this? 8 106
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question