Go to the first, previous, next, last section, table of contents.


What is a link?

Let's divide the concept of a (computer) file into its contents and its name in a directory listing.

A given content can have more than one file name that refers to it. When I do `ls -li /bin/*zip /bin/*cat' I see:

   2391 -rwxr-xr-x   1 root     root        16568 Aug 10  1996 /bin/cat
   2050 -rwxr-xr-x   3 root     root        45056 Aug 20  1996 /bin/gunzip
   2357 lrwxrwxrwx   1 root     root            4 Sep 18  1996 /bin/gzcat -> gzip
   2050 -rwxr-xr-x   3 root     root        45056 Aug 20  1996 /bin/gzip
   2050 -rwxr-xr-x   3 root     root        45056 Aug 20  1996 /bin/zcat

In this example, the file names `/bin/gunzip', `/bin/gzip' and `/bin/zcat' all refer to the same file content: they all refer to inode 2050, which points to certain disk blocks where the file content is stored. The inode also stores the permission bits, the file's owner's user id and owner-group id, timestamps, ext2 attributes (including whether or not the file is e2compressed), data length, and other things.

The link count of `3' indicates that there are three names currently in the filesystem that correspond to the same file (or, more accurately, to the same inode).

By coincidence, all three of these links (names) happen to be in the same directory in the above example, but in general they needn't be; they need only be in the same filesystem.

`/bin/cat', on the other hand, is a different file: you can see that it has a different length, a different modification date, and you would guess that its data is stored in different blocks on the hard drive.

`/bin/gzcat', on the third hand, is a symbolic link. Symbolic links are a different kettle of fish altogether. In general, when we say `a file with multiple links', we're not including symbolic links, but only those multiple file names that share the same inode number. The `link count' always excludes symbolic links from the count.


Go to the first, previous, next, last section, table of contents.