Lesson 4 | Symbolic links |
Objective | Use Symbolic Links to simplify Software Maintenance. |
Use Symbolic Links to simplify Software Maintenance
A symbolic link represents an alias for a file. A symbolic link shows up in ls -l
directory listings like this:
lrwxrwxrwx 1 root system 21 Aug 14 1996
unix -> /usr/lib/unix
This means that the link named unix
points to the file /usr/lib/unix. A reference to the link name is transformed into a reference to the target file.
Creating a symbolic link
Links are created with the ln
command:
ln –s $HOME/project/command $HOME/bin/command
The syntax of the ln
command is like that of the copy
command.
The above command creates a file $HOME/bin/command, which is a symbolic link to the file $HOME/project/command.
You must use the –s
option of the ln
command to create a symbolic link because this will allow you to link across filesystems and see the name of the link when you run ls –l
.
Without the ability to see the name of the link, you have no way of knowing the name to which a file is linked.
Any finite set of training data also contains sampling error.
Creating Symbolic Links
Link Files
The concept of a link in UNIX is for
file sharing. A link file is created by the system when a symbolic link is created to an existing file.
The link file points to the existing file, which allows the users to rename an existing file and share it without duplicating its contents.
For the kernel, every file has one inode, but it may have several names of links, all of which map into the inode. The concept of the
symbolic link in UNIX is a creation of BSD but is presently available on almost all versions of UNIX .
The symbolic link is also called soft link and a
symbolic link may be a file containing the pathname of another file or directory, and it can cross file system boundaries. In contrast to soft link, it is a hard link.
There are two typical hard links:
one is written as .; the other is ..
- . in a directory is a hard link to the directory itself, and
- .. of the directory is a hard link to its parent directory.