Skip to main content
Source Link

I'm not trying to answer your question, but...

Every entry in a directory is a "hard link", including symbolic links.

That's wrong.

Actually, the first part is right. Every entry in a directory is a hard link. But, a symbolic link is not an entry in a directory. A symbolic link is a file, just like any other file, except a flag in its inode tells the OS that when a program tries to access the symlink, the OS should treat the access specially.*

The author probably knew that, but they were trying to explain hard links, not symbolic links, and they got lazy. If they were less lazy, they might have said,

Every entry in a directory is a hard link. Even the entry for a symbolic link (a symbolic link actually is a special kind of file) is a "hard link" to the symbolic link file.


* The special treatment, when a program tries to access a symlink,** is;

  1. open the symlink file,
  2. read a pathname from the symlink file,
  3. close the symlink file,
  4. access the target file (i.e., the file named by the pathname that was read from the symlink file) as if that was the file that the program asked to open in the first place.

If the target file turns out to be another symlink, then the process repeats, either until a non-symlink file is found, or until the ELOOP error code is returned.


** There are a few system calls and/or options in system calls that don't "follow" symbolic links. Those are necessary because otherwise, how could any program (e.g., ls) ever give you information about symbolic links, or create or destroy symbolic links?

Post Made Community Wiki by Solomon Slow