Please subscribe to RSS Feed! :)

I just gave an impromptu lesson on symbolic links (symlinks) and hard links, complete with ASCII art, in #ubuntu-offtopic, and Topyli commented that simple explanations of this for beginners are hard to find, so here's a summary.
The purpose of a link is to allow you to have two (or more) paths to access the same data without having the data exist on disk multiple times, thus giving convenience without sacrificing disk space. So why are there two kinds of links and how do they work?
Symlinks (ln -s REALPATH LINK) work like this:
LINK --> REALPATH --> DATA
While hard links (ln PATH1 PATH2) work like this:
PATH1 --> DATA <-- PATH2
See what's happening here? In the symlink case, your link points to another path, which points to the data. In the hard link case, two paths point to the same data directly. I think I could get a lesson on pointers in C out of this ASCII art if I wanted to. If you want a bit more background, your hard disk's filesystem contains a table of inode numbers, which is just like the Index at the back of a book. Symlinks are when you get "(see also: rubber ducky)" and hard links are when you get "Rubber ducky: 5" and "Sesame Street: 5" both showing up in the Index. Since we can have multiple filesystems mounted on one machine (for example my /home is on a separate partition), it is important to note that while a symlink can point to something located on another disk (or in a book "Further reading: Little Red Riding Hood"), a hard link only knows about data on its own filesystem (ie same partition). So, if you want to link from your hard disk to a flash drive, you need to use a symlink. This makes sense since your hard disk can't know if your flash drive rearranges things while it's plugged into another computer.
How do these show up in ls? Hard links look like normal files. For symlinks ls -l --color will show LINK -> REALPATH. If REALPATH is deleted, this will be highlighted as red text on a black background.
Speaking of deletion, how does that work? Well, if you remove LINK, REALPATH and DATA will still exist. If you remove REALPATH, DATA goes away too and LINK just points at nothing (though if you add REALPATH back, LINK will start working again, as it only goes by filename). As for hard links, DATA goes away once no more inode numbers point to it. As mentioned before, hard links point directly to the data, so this means removing all links and the original filename. So if I remove the original filename (PATH1), PATH2 will still point to DATA.
I hope that's a straightforward enough explanation of how it works.