We have seen how to create copies of files. Now we will see how to
create crossreferences to files. Imagine we have a file that every
user needs in his home directory. If we put a copy in every users
directory this would use up masses of disk space. To stop wastage
like this happening UNIX allows us to define crossreferences to other
files: links. We can create a crossreference using the
ln command.
There are two types of links, hard and soft links. Hard links are just
another name for the same file. a hard link can not be distinguished
in any way from the original name of the file. The only way to
recognise a file which has hard links to it is by inspecting the link
counter in the directory listing, if this is greater than one a file
has hard links to it. Deleting a file with hard links to it can be
problematic, as all hard links to it have to be deleted. Soft links
however are much easier and safer. They are clearly distinguishable
from the original filename and when the original file is deleted they
just point into a void.