Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://80249]
[LanX]: ;-p
shmem spent 3 hours chasing a bug related to variable scoping
[shmem]: is there an equivalent to my in python? or 'use strict' ?
[LanX]: I doubt
[LanX]: only nonlocal in Py3
[shmem]: so, python sucks
LanX NSFW!!!

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2018-03-20 17:53 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (256 votes). Check out past polls.