hard link identification

Robert Bonomi bonomi at mail.r-bonomi.com
Tue May 22 21:24:31 UTC 2012


<dteske at freebsd.org> wrote;
>
> For directories, the link-count is quite obviously the number of filesystem
> entities contained within.

That is *INCORRECT*.  The link-count on a directory is the number of dir-
ectory entries (file names) tht resolve to it, just as with any other file.
The count starts at *TWO* -- one for the directory name itself, plus one 
for the '.' self-refernce 'in' that directory -- plus one for the '..' 
reference in each and every sub-directory that is in that directory, PLUS 
one (albeit rare) for any other hard-linked names  that also resolve to that 
diretory.

To wit:
  $  mkdir foo        # 'ls -l foo' will show a link-count of 2
  $  touch foo/bar    # 'ls -l foo' will show a link-count of 2
  $  mkdir foo/baz    # 'ls -l foo' will show a link-count of 3
  $  ln -s foo foo2   # 'ls -l foo' will show a link-count of 3
  $  ln foo quux      # 'ls -l foo' will show a link-count of 4



More information about the freebsd-questions mailing list