Hard and Soft Links
1.5.2 Hard and Soft Links
A filename included in a directory is called a file hard link, or more simply a link. The same
file may have several links included in the same directory or in different ones, thus several
filenames.
The Unix command:
$ ln f1 f2, is used to create a new hard link that has the pathname f2 for a file identified by the pathname f1.
Hard links have two limitations:
• Users are not allowed to create hard links for directories. This might transform the
directory tree into a graph with cycles, thus making it impossible to locate a file
according to its name.
• Links can be created only among files included in the same filesystem. This is a
serious limitation since modern Unix systems may include several filesystems located
on different disks and/or partitions, and users may be unaware of the physical
divisions between them.
In order to overcome these limitations, soft links (also called symbolic links) have been
introduced. Symbolic links are short files that contain an arbitrary pathname of another file.
The pathname may refer to any file located in any filesystem; it may even refer to a
nonexistent file.
The Unix command:
$ ln -s f1 f2
creates a new soft link with pathname f2 that refers to pathname f1. When this command is
executed, the filesystem creates a soft link and writes into it the f1 pathname. It then inserts—
in the proper directory—a new entry containing the last name of the f2 pathname. In this way,
any reference to f2 can be translated automatically into a reference to f1.
File Types
Unix files may have one of the following types:
• Regular file
• Directory
• Symbolic link
• Block-oriented device file
• Character-oriented device file
• Pipe and named pipe (also called FIFO)
• Socket
The first three file types are constituents of any Unix filesystem.
Device files are related to I/O devices and device drivers integrated into the kernel. For
example, when a program accesses a device file, it acts directly on the I/O device associated
with that file.
Pipes and sockets are special files used for interprocess communication.
Comments
Post a Comment