symbolic links
or
symlink
) is an entry that points to another
directory or file. This is different to a hard link, because a hard link is a duplicate
entry that references an inode, while a symbolic link references a specific path.
Symbolic links can not only be moved around between filesystems; we can also
create a symbolic link to a directory as well. To illustrate how a symbolic link works,
let's create one. In my case, I'll delete
file3
and recreate it as a symbolic link. We'll
again use the
ln
command:
rm file3
ln -s file1 file3
Chapter 5
[
137
]
With the
-s
option of
ln
, I'm creating a symbolic link. First, I deleted the original
hard link with the
rm
command (which doesn't disturb the original file,
file1
) and
then created a symbolic link, also named
file3
. If we use
ls -i
again, we'll see that
file3
does not have the same inode number as
file1
:
Figure 5.10: Output of ls -i after creating a symbolic link
Notice that the inode numbers of each file are all different. At this point, the main
difference compared with a hard link should become apparent. A symbolic link is
not a clone of the original file; it's simply a pointer to the original file's path. Any
commands you execute against
file3
are actually being run against the target that
the link is pointing to. Hard links on the other hand, point directly to the file.
In practice, symbolic links are incredibly useful when it comes to server
administration. However, it's important not to go crazy and create a great number
of symbolic links all over the filesystem. This certainly won't be a problem for you
if you are the only administrator on the server, but if you resign and someone
takes your place, it will be a headache for them to figure out all of your symbolic
links and map where they lead to. You can certainly create documentation for your
symbolic links, but then you'd have to keep track of them and constantly update
documentation. My recommendation is to only create symbolic links when there are
no other options, or if doing so benefits your organization and streamlines your file
layout.
Getting back to the subject of symbolic links versus hard links, you're probably
wondering which one you should use and when to use it. The main benefit of a hard
link is that you can move either file (the link or the original) to anywhere on the same
filesystem and the link will not break. This is not true of symbolic links; however, if
you move the original file, the symbolic link will be pointing to a file that no longer
exists at that location. Hard links are basically duplicate entries pointing to the same
object, and thus have the same inode number, so both will have the same file size
and content. A symbolic link is a pointer to the file's path—nothing more, nothing
less.
Managing Files and Directories
Do'stlaringiz bilan baham: |