A hard link is defined as a pointer to an inode. A soft link, also known as a symbolic link, is defined as an independent file pointing to another link without the restrictions of hard links.
What is the difference between a file and a hard link? A hard link points to an inode, so what is a file? The inode entry itself? Or an inode with a hard link?
Let's say I create a file with touch. Then an inode entry is created in the inode table. And I create a hard link, which has the same inode number as the file. So did I create a new file? Or is the file just defined as an inode?
Best Answer
The very short answer is:
Unix files and directories work exactly like files and directories in the real world (and not like folders in the real world); Unix filesystems are (conceptually) structured like this:
Keeping this metaphor in mind, and specifically keeping in mind that Unix directories work like real-world directories and not like real-world folders explains many of the "oddities" that newcomers often encounter, like: why can I delete a file I don't have write access to? Well, for one, you're not deleting the file, you are deleting one of many possible names for the file, and in order to do that, you only need write access to the directory, not the file. Just like in the real world.
Or, why can I have dangling symlinks? Well, the symlink simply contains a pathname. There is nothing that says that there actually has to be a file with that name.
The difference between a file and a hard link is the same as the difference between you and the line with your name in the phone book.
A file is an anonymous piece of data. That's it. A file is not an inode, a file has an inode, just like you are not a Social Security Number, you have a SSN.
A hard link is a name for a file. A file can have many names.
Yes.
No. A hard link doesn't have an inode number, since it's not a file. Only files have inode numbers.
The hardlink associates a name with an inode number.
Yes.
No. The file has an inode, it isn't an inode.