Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Hard links vs symbolic links

by merlyn (Sage)
on May 14, 2001 at 20:34 UTC ( #80249=note: print w/ replies, xml ) Need Help??


in reply to Quiz for Newbie

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


Comment on Hard links vs symbolic links

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://80249]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (17)
As of 2014-07-28 19:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (206 votes), past polls