Steve Crane wrote:
>
> On Sat, Apr 10, 1999 at 09:49:06PM -0500, Raul Beltran wrote:
> > ln -s <source> <target>
> >
> > the '-s' option creates a symbolic link instead of a hard link.
>
> I've often wondered just what is meant by 'symbolic link' and 'hard
> link'. The man page for ln mentions, but doesn't explain them. Can
> someone explain the difference or point me to some docs that do explain
> the difference.
>
>From "Linux The Complete Reference":
Links let you give a single file more than one name. Files are actually
identified by the system by their 'inode number', which is just the
unique file system indentifier for the file. A directory is actually a
listing of indoe numbers with their corresponding filenames. Each
filename in a directory is a link to a particular inode.
Hard Links
The ln command is used to create mulitple links for one file. For
example, let's say that you have a file called foo in a directory.
Using ls -i you can look at the inode number for this file.
/home/larry# ls -i foo
22192 foo
/home/larry#
Here, foo has an inode number of 22192 in the file system. You can
create another link to foo, named bar, as follows:
/home/larry# ln foo bar
With ls -i you see that the two files have the same inode number:
/home/larry# ls -i foo bar
22192 bar 22192 bar
/home/larry#
Now, specifying foo or bar will access the same file. If you make
changes to foo, those changes appear in bar as well. For all purposes
foo and bar are the same file. These links are know as HARD LINKS
because they create a direct link to an inode. Note that you can hard
link files only when they are on the same file system; SYMBOLIC LINKS
don't have this restriction. When you delete a file with rm you are
actually only deleting one link to a file. If you use the command:
/home/larry# rm foo
then only the link named foo is deleted, bar will still exist. A file
is only truly deleted on a system when it has no links to it. Usually,
files have only one link, so using the rm command deletes the file.
However, if a file has multiple links to it, using rm will delete only a
single link; in order to delete the file, you must delete all links to
the file. The ls -l command displays the number of links to a file
(among other information).
/home/larry# ls -l foo bar
-rw-r--r-- 2 root root 12 Aug 5 16:51 bar
-rw-r--r-- 2 root root 12 Aug 5 16:51 foo
/home/larry#
The seond column in the lising, "2", specifies the number of links to
the file.
As it turns out, a directory is just a file containing information about
link-to-inode assoications. Also, each directory contains at least two
hard links: "." (a link pointing to inself) and ".." (a link pointing to
the parent directory). The root directory (/) ".." just points back to
/. In otherwords the parent of the root directory is the root directory
itself. (And now you know where www. slashdot.com got it's name! -JLK)
A SYMBOLIC link lets you give a file another name but doesn't link that
name to the inode number. With the command
/home/larry# ln -s foo bar
you will create a symbolic link named bar that points to the file foo.
If you use ls -i you will see that you have two different files indeed.
/home/larry# ls -i foo bar
22195 bar 22192 foo
/home/larry#
However using ls -l we see that the file bar is a symlink pointing to
foo:
/home/larry# ls -l foo bar
lrwxrwxrwx 2 root root 3 Aug 5 16:51 bar -> foo
-rw-r--r-- 2 root root 12 Aug 5 16:51 foo
/home/larry#
The file permissions on a link are not used. (they always appear as
rwxrwxrwx). Instead, the permissions on the symbolic link are
determined by the permissions on the target of the symbolic link. You
can create a symbolic link to a file that DOESN'T exist, but not a hard
link. Symbolic links are helpful because they indentify the file they
point to; with hard links there is no easy way to determine which files
are linked to the same node. Links are used in many places in the Linux
system. Symbolic links are especially important to the shared library
images in /lib. --end of quote---
Pardon me for included the whole section, but it contained information
that I wanted to review for myself and I thought I would just share it
since the question was raised.
--
JLK
Linux, because it's STABLE, the source code is included, the price is
right.
--
To get out of this list, please send email to [EMAIL PROTECTED] with
this text in its body: unsubscribe suse-linux-e
Check out the SuSE-FAQ at http://www.suse.com/Support/Doku/FAQ/ and the
archive at http://www.suse.com/Mailinglists/suse-linux-e/index.html