4.5.5 Links
There are two methods of associating a file foo with a different
filename bar.
-
a hard link is a duplicate name for an existing file (ln
foo bar),
-
a symbolic link, or "symlink", is a special file
that points to another file by name (ln -s foo
bar).
See the following example for the changes in link counts and the subtle
differences in the result of the rm
command.
$ echo "Original Content" > foo
$ ls -l foo
-rw-r--r-- 1 osamu osamu 4 Feb 9 22:26 foo
$ ln foo bar # hard link
$ ln -s foo baz # symlink
$ ls -l foo bar baz
-rw-r--r-- 2 osamu osamu 4 Feb 9 22:26 bar
lrwxrwxrwx 1 osamu osamu 3 Feb 9 22:28 baz -> foo
-rw-r--r-- 2 osamu osamu 4 Feb 9 22:26 foo
$ rm foo
$ echo "New Content" > foo
$ cat bar
Original Content
$ cat baz
New Content
The symlink always has nominal file access permissions of
"rwxrwxrwx", as shown in the above example, with the effective access
permissions dictated by the permissions of the file that it points to.
The .
directory links to the directory that it appears in, thus
the link count of any new directory starts at 2. The ..
directory
links to the parent directory, thus the link count of the directory increases
with the addition of new subdirectories.