Solved

Hard Link? Soft Link ?

Posted on 1998-09-13
4
1,785 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Perl Awk Need Help 3 94
isEverywhere  challenge 19 64
Fibonacci challenge 11 84
Not needed 13 57
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now