The very short answer is:
- a file is an anonymous blob of data
- a hardlink is a name for a file
- a symbolic link is a special file whose content is a pathname
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:
- a file is an anonymous blob of data; it doesn't have a name, only a number (inode)
- a directory is a special kind of file which contains a mapping of names to files (more specifically inodes); since a directory is just a file, directories can have entries for directories, that's how recursion is implemented (note that when Unix filesystems were introduced, this was not at all obvious, a lot of operating systems didn't allow directories to contain directories back then)
- these directory entries are called hardlinks
- a symbolic link is another special kind of file, whose content is a pathname; this pathname is interpreted as the name of another file
- other kinds of special files are: sockets, fifos, block devices, character devices
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.
My question is simply what is the difference of a file and a hard link ?
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.
Hard link is pointing to an inode, so what is a file ? Inode entry itself ? Or an Inode with a hard link ?
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.
Let's say, I create a file with touch, then an Inode entry is created in the Inode Table.
Yes.
And I create a hard link, which has the same Inode number with the file.
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.
So did I create a new file ?
Yes.
Or the file is just defined as an Inode ?
No. The file has an inode, it isn't an inode.
Best Answer
There is absolutely no difference between a temporary file and a regular file.
A temporary file is a regular file, and a regular file is "regular" as opposed to being a directory, or a device special file, or named pipe etc.
The only difference is, as you point out, the typical use of the file. When a program or script creates a "temporary file", it is typically a regular file that is used to store temporary data that is not needed beyond the lifetime of the process that created it. Such files are often created in
$TMPDIR
.POSIX defines:
It does not, however, care to say anything about the definition of a "temporary file", because it's not a specific file type (rather, a way of using regular files).