All entries in the filesystem are "hard links". A hard link goes from a name to an "inode number". The "inode" contains information about the file's permissions, ownership, type, and location on disk if any.

The link operator makes additional names that have the same inode number, so that they are really the same file, but with two (or more) different names. There's no "real" name; they are all equally valid. Only when you've removed the last name for an inode will the system consider removing the data. So the rm command, or the unlink operator, is removing a name, not an inode.

The symlink operator creates an inode with a name "pointer". When you reference the inode, its contents are substituted for the name, and the name lookup continues. Thnk of the "see ____" entry in an index. Now, that name might not be reachable or still exist, in which case you'll get a file-not-found error. Or it might in turn have another symlink... you're allowed to hop some small number of times (like 8 or 16, if I recall, depending on the kernel).

Because inode numbers are within a particular "device" (think: "drive partition"), you can't have a "hard link" from one "device" to another. But you can "symlink" anywhere you want. Also, to keep the nice orderly hierarchy of nested directories clean, only the superuser can "hard link" to a directory, but anyone can create a symlink to a directory.

-- Randal L. Schwartz, Perl hacker


In reply to Hard links vs symbolic links by merlyn
in thread Quiz for Newbie by bambam

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.