[WinMac] Soft vs. Hard Links was: Re: (Lin) KDE 2.2.1 trash problem.


Subject: [WinMac] Soft vs. Hard Links was: Re: (Lin) KDE 2.2.1 trash problem.
From: Michael Eilon (mgeilon[at]cyllene.uwa.edu.au)
Date: Mon Jun 03 2002 - 12:37:24 EDT


At 9:18 PM +0800 2/6/02, Romeyn Prescott wrote:
[...]
>[prescor@rom1 prescor]$ ls -la
>total 194232
>drwxr-xr-x 45 prescor prescor 4096 May 31 12:46 .
>drwxr-xr-x 9 root root 4096 May 29 13:54 ..
>-rw-rw-r-- 1 prescor prescor 104857600 Nov 9 2000 100.img
>drwx------ 2 prescor prescor 4096 Apr 4 08:13 .AbiSuite
>drwxr-xr-x 3 prescor prescor 4096 Apr 10 17:47 AIMsounds
>drwxr-xr-x 5 prescor prescor 4096 May 1 18:54 .AppleDesktop
>drwxr-xr-x 2 prescor prescor 4096 Apr 27 22:02 .AppleDouble
>drwxr-srwx 9 prescor prescor 4096 Apr 10 17:13 Applications
>-rw------- 1 prescor prescor 5040 Jun 1 20:17 .bash_history
>-rw-r--r-- 1 prescor prescor 24 May 23 13:43 .bash_logout
>-rw-r--r-- 1 prescor prescor 191 May 23 13:43 .bash_profile
>-rw-r--r-- 1 prescor prescor 124 May 23 13:43 .bashrc
>-----
>
>The stuff on the left has to do with permissions.
>
>The numbers have something to do with...I'm not really sure...

It's the number of hard links to the file/directory.

In most Unixen (including Linux) there are two kinds of links that can be
made to a file or directory; soft links and hard links.

The former are analogous to the Mac concept of an alias (or the Windows
concept of a shortcut), and are the most common kind of links.

Hard links are a different story altogether, and messing with them
(especially with respect to directories) can cause filesystem problems.

Basically, all files on a Unix filesystem have a "front end" and a "back
end". The back end is the file's contents on the disk, and the front end
is a hard link to that disk location.

The file entry that you see when you do an "ls -al" is basically the hard
link "front end" of the file.

Now in Unix, you can create multiple hard links which point to the same
file contents on disk. They simply appear as separate entries in an "ls
-al" of the directory (or you can create hard links to a file in another
directory, so long as they're all on the same physical HD).

All hard links to a file are the same, regardless of which was created
first, and you can't normally tell when a file has more than one hard link
to it, which is why there's an extra column listing the hard links just
after the file permissions. (Soft links, on the other hand, are easily
identified because they have an initial letter "l" in the permissions
field, just like the way directories start with a "d", and normal files
start with a "-".)

Sometimes, in Unix documentation related to file deletion, you'll see
references to "unlinking" a file; that's basically what the "rm" command
does -- it removes the specified hard link from a file. Most files have
only one hard link to them, so an "rm" effectively deletes the file,
because there are no more hard links to the file's contents, which are then
"lost" or deleted.

If you try to "rm" a file with more than one hard link, all that happens is
that the number of hard links decreases by 1. The file can still be
accessed using its other hard link(s).

Directories are more complicated, because the filesystem automatically
creates a hard link to it -- called "." -- when you create it. That's
usually the first entry when you do an "ls -al" of the directory. In
addition to this, all subdirectories get created with hard links -- called
".." -- to their "parent" directories. These usually appear as the second
entry when you do an "ls -al" of a directory. (Hence the command "cd .."
moves you up one directory.)

Sooo, for instance, I can tell that the "Applications" directory in your
listing above, has 7 subdirectories, for a total of 9 hard links (1 for the
"Applications" entry, one for the "." entry inside it, and 1 each for the
".." entries in the seven subdirectories).

--

Anyway, I could go on ad nauseum. Apologies for the length of this email... I'm currently doing a "critical review" of the literature for my thesis writeup, which is a difficult, painful, frustrating process. So when someone mentions something I actually know a little about, the floodgates open :-\

Oh well.

Cheers,

Michael Eilon Assistant computer manager Dept. of Physics University of Western Australia

<mgeilon@cyllene.uwa.edu.au>

*** Windows-MacintoshOS Cooperation List *** FAQ: http://www.darryl.com/winmacfaq/ Archive: http://www.darryl.com/winmac/

To unsubscribe, send mail to winmac-unsubscribe@iffy.com



This archive was generated by hypermail 2b28 : Mon Jun 03 2002 - 12:38:01 EDT