Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 1 Nov 96 17:25:09 -0500
From:      curt@kcwc.com (Curt Welch)
To:        Questions@FreeBSD.org
Cc:        Skynet1@cris.com
Subject:   Links (was: Re: your mail)
Message-ID:  <9611012225.AA05884@mail.kcwc.com>

next in thread | raw e-mail | index | archive | help
On Wed, 30 Oct 1996 Skynet1@cris.com wrote:

> With the LS command, what is the number after the permission bits  
specify?

This is a very basic Unix question that everyone needs to
know.  But, trying to understand it by reading the man pages
isn't so easy.

Doug answered:
> -rw-r--r--  1 dwhite  1000       1893 Aug 28 20:05 upgrade-instructions
>             ^
> This is a regular file, with no symlinks or hard links.  


Doug knows what he's taking about, but his answer is
a bit confusing.  What he should have said is more like:
It's a regular file with 1 hard link, but no extra
hard links.

The number is the number of hard links (i.e. names) the
file has.

On Unix, all the information about a file is stored in its
inode -- expect it's name.  File names are stored in the
directories (which are like files themselves), along with
the inode number of the file.  This structure allows a
single file (inode) to have multiple names (or in Unix terms
- hard links).  Files have 1 hard link when they are
created.  Other links can be created using the ln(1)
command.

A file with multiple hard links is really just one file with
multiple names.  None of the names are more valid or
important than the others.  For example, you can change the
mode of the file using chmod(1) with any of it's names, and
a file won't be removed until all it's hard links are
removed.

Before BSD, there was no rename() system call in Unix.
Files were renamed by first creating a new hard link to the
file and then removing the old link.  The system call to
remove a file isn't called delete() or remove(), it's called
unlink().  There is no way to remove a file, all you can
do is unlink it.  It goes away only after the last hard
link has been removed -- which is why the link count
is stored in the inode -- and is shown with the -l option
of ls.

Symbolic links (a.k.a. symlinks/soft links) were added
many years later by the BSD guys.  Symlinks are the
"correct" way to create a file name alias.  Hard links,
though simple and elegant, have far too many hidden
side effects and limitations.  Symlinks, unlike
hard links, aren't just another name for the
same file.  A symlink is a special type of file which
points to another file by name (not by inode number).

Symbolic links are created using ln(1) with the -s option.

Curt Welch
curt@kcwc.com



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