Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 May 2012 16:26:18 -0500 (CDT)
From:      Robert Bonomi <bonomi@mail.r-bonomi.com>
To:        dteske@freebsd.org, freebsd-questions@freebsd.org, freebsd@dreamchaser.org
Subject:   RE: hard link identification
Message-ID:  <201205222126.q4MLQImN071457@mail.r-bonomi.com>
In-Reply-To: <0ae301cd385c$31813370$94839a50$@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help

<dteske@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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201205222126.q4MLQImN071457>