> Date: Fri, 26 Jun 1998 12:40:02 -0400
> From: "James H.G. Redekop" <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Subject: Re: hardlink vs. symlink
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset=us-ascii
> Content-Transfer-Encoding: 7bit
>
> Chris Frost wrote:
> >
> > How do hard links and sym links differ?
>
>  A hard link fools the system into thinking the file linked to
> is *right there* by actually duplicating the file header and
> pointing it to where the rest of the real file lies.  It can
> only be used for files, and only for files on the same partition.

Close, but I wouldn't call it "fooling", and there is no duplication of any
header info.

Files on a Unix (or Linux) system are actually managed by i-node number. They
are made accessible through the filesystem namespace by directory entries. Each
directory entry consists of, basically, a name and an i-node number:

        mydata          1403
        mydata.bak      1279
        newdir          1830

All the rest of the info (permissions, access time, etc) is stored in the
i-node.

Thus each files has at least one hard link (otherwise you can't reference the
file by name). You can create additional hard links to give a file multiple
names, but because the i-node number references the same filesystem as that in
which the directory entry resides, you cannot cross filesystem boundaries.

Within the inode there is a counter which keeps track of the number of active
(hard) links; this can be displayed with "ls -l". When this counter goes down
to zero and the file is closed, it is deleted. Thus the OS does not really
provide file deletion functionality, just an unlink capability.

The fact that the file does not disappear until it is closed has some
advantages. You can safely delete a file without fearing that you're going to
bomb some program currently using the file; and you can unlink a temp file that
you have open, knowing that it will be deleted as soon as you close it.

>  A sym link is a small file which contains the true path to
> the file linked to.  It doesn't fool anyone, it just points.
> It can be used for directories and across partitions.  Following
> a chain of symlinks can slow file access down.

Right. Symlinks have three advantages: they can be used for non-regular-files
(e.g., directories), they can cross filesystems, and the target does not have
to exist (e.g., they can point to a file that is only sometimes present, e.g.,
a network-mounted or floppy-mounted file).

-- 
Chris Tyler                       <[EMAIL PROTECTED]>
Global Proximity Corporation      http://Global.Proximity.ON.CA/
Internet and Computer Consulting  (519) 469-3439 / fax (519) 469-8653


-- 
  PLEASE read the Red Hat FAQ, Tips, Errata and the MAILING LIST ARCHIVES!
http://www.redhat.com/RedHat-FAQ /RedHat-Errata /RedHat-Tips /mailing-lists
         To unsubscribe: mail [EMAIL PROTECTED] with 
                       "unsubscribe" as the Subject.

Reply via email to