From owner-freebsd-questions Fri Nov 1 14:27:55 1996 Return-Path: owner-questions Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id OAA07731 for questions-outgoing; Fri, 1 Nov 1996 14:27:55 -0800 (PST) Received: from relay2.UU.NET (relay2.UU.NET [192.48.96.7]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id OAA07681 for ; Fri, 1 Nov 1996 14:27:49 -0800 (PST) Received: from mail.kcwc.com by relay2.UU.NET with SMTP (peer crosschecked as: [206.139.252.2]) id QQbnzt20692; Fri, 1 Nov 1996 17:26:42 -0500 (EST) Received: by mail.kcwc.com (NX5.67c/NeXT-2.0-KCWC-1.0) id AA05884; Fri, 1 Nov 96 17:25:09 -0500 Date: Fri, 1 Nov 96 17:25:09 -0500 From: curt@kcwc.com (Curt Welch) Message-Id: <9611012225.AA05884@mail.kcwc.com> Received: by NeXT.Mailer (1.87.1) Received: by NeXT Mailer (1.87.1) To: Questions@FreeBSD.org Subject: Links (was: Re: your mail) Cc: Skynet1@cris.com Sender: owner-questions@FreeBSD.org X-Loop: FreeBSD.org Precedence: bulk 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