HARDLINKS AND SYMLINKS
Today we will test your virtual imagination capabilities !
The main difference between hardlinks and symlinks ( symbolic or
softlinks ) are:
1.) You cannot make a hardlink to a directory.
2.) If you remove the original file of a hardlink the link will still
show you the content of the file.
3.) A symlink can link a directory
4.) The symlink is useless as you remove the original file.
All this might seem hard to grasp, but let´s explain:
A little experiment to show the case.
( Making a new directory for our test )
( Move in the directory )
( Make a file called fileA )
Type in some funny lines of text
< Esc >
ZZ ( save the file )
So, we made a ¨fileA¨ in a new directory called ¨Test¨
in your /home.
( Making a hardlink )
ls -il fileA fileB
( The ¨i¨ argument will show the inode on the HD )
This is what you get:
-rw-r--r-- 2 bruno bruno
21 May 5 15:55 fileA
2 bruno bruno 21
May 5 15:55
you can see that both fileA and fileB have the same inode number (
1482256 ), also both files have the same file permissions and the same
size, because that ´size´ is on the same inode it does not
extra space on your HD !
Now if we would remove the original ¨fileA¨
and have a look at the content of the ¨link¨ fileB
you will still be able to read the funny line
of text you typed. ( MAGIC ! )
Staying in the same test directory as above we make a symlink:
ln -s fileB fileC
$ ls -il fileB fileC
This is what you´ll get:
1 bruno bruno 21 May 5 15:55
1 bruno bruno
5 May 5
16:22 fileC -> fileB
notice the inodes are different and the link got a ¨l¨ before
rwxrwxrwx . The link has different permissions than the original file
because it is just a symbolic link, its real content is just a string
pointing to the original file. The size of the symlink ( 5 ) is the
size of it´s string. ( The "->
fileB" at the end shows you where the link points to )
Will show the same funny text.
Now if we remove the original file:
and check the Test directory
you will see the link fileC is still there, but if we do
it will tel you that there is no such file or directory !! Though
will still give you:
lrwxrwxrwx 1 bruno bruno
5 May 5 16:22
fileC -> fileB
But the link is obsolete ! ( hope you´re still with me )
O.K. The test is over, you can delete the Test directory
$ rm -rf Test
( ¨r¨ stands for recursive ¨f¨ is force )
-rf" is very powerfull, if ever someone wants to play a
trick on you and tells you to do "rm -rf /" as root, you might
loose all your files and directories on your / partition !!!
Not dizzy yet ? Wait till next week when we come to the real stuff !
-- May 5 2003 ( Revised Dec 10 2005 ) --