[unix] What is the difference between a symbolic link and a hard link?

A simple way to see the difference between a hard link and a symbolic link is through a simple example. A hard link to a file will point to the place where the file is stored, or the inode of that file. A symbolic link will point to the actual file itself.

So if we have a file called "a" and create a hard link "b" and a symbolic link "c" which all refer to file "a" :

echo "111" > a
ln a b
ln -s a c

The output of "a", "b", and "c" will be :

cat a --> 111
cat b --> 111
cat c --> 111

Now let's remove file "a" and see what happens to the output of "a", "b", and "c":

rm a
cat a --> No such file or directory
cat b --> 111
cat c --> No such file or directory

So what happened?

Because file "c" points to file "a" itself, if file "a" is deleted then file "c" will have nothing to point to, in fact it is also deleted.

However, file "b" points to the place of storage, or the inode, of file "a". So if file "a" is deleted then it will no longer point to the inode, but because file "b" does, the inode will continue to store whatever contents belonged to "a" until no more hard links point to it anymore.