9.3 Links

Links are pointers between files. With links, you can have files exist in many locations and be accessible by many names. There are two types of links: hard and soft.

Hard links are names for a particular file. They can only exist within a single filesystem and are only removed when the real name is removed from the system. These are useful in some cases, but many users find the soft link to be more versatile.

The soft link, also called a symbolic link, can point to a file outside of its filesystem. It is actually a small file containing the information it needs. You can add and remove soft links without affecting the actual file. And since a symbolic link is actually a small file containing its own information, they can even point at a directory. It's rather common to have /var/tmp actually be a symbolic link to /tmp for example.

Links do not have their own set of permissions or ownerships, but instead reflect those of the file they point to. Slackware uses mostly soft links. Here is a common example:

% ls -l /bin/sh
lrwxrwxrwx   1 root     root     4 Apr  6 12:34 /bin/sh -> bash

The sh shell under Slackware is actually bash. Removing links is done using rm. The ln command is used to create links. These commands will be discussed in more depth in Chapter 10.

It's very important to be careful about symlinks in particular. Once, I was working on a machine that was consistently failing to back-up to tape each night. Two symlinks had been made to directories beneath each other. The back-up software kept appending those same directories to the tape until it was out of space. Normally, a set of checks will prevent creating a symlink in this situation, but ours was a special case.