Hard links and Symbolic links

Sorry, no sausage links.

So whats a hard link?

A hard link is just another name for a file that already exists on a operating system. So one file can have multiple hard links, or names. Hard links can also be created for other hard links. A name for a name for a file.

To create a hard link, you use the ln command.

$ ln <source> <linkname>

Source being the name of the original file and linkname being the nickname for the new file.

Thats it, you’ve created a hard link.

Now to be clear, the computer is making a new file with the data content linked to the original file. So when the original file is changed, the new file is changed too. But if you delete the original file, the new one will still be there.

So whats a symbolic link?

So, a symbolic link is a file that will point you to another file.

To create a symbolic link you and use the same ln command, just with a -s flag. Like so:

$ ln -s <source> <linkname>

Looks familiar right?

So the main differences between the two is that this symbolic link does not contain any data or info from the original, or source, file. And because it just points to where the original file is, you can point to not only files, but directories too. (Hard links can’t do that.) But, if you use a symbolic link, don’t delete the original file. Then the symbolic link will point to nothing. Just a spot where you’re file or directory used to be.

Questions?

Well that’s what google is for.