Deleting files and Inodes

1.7k Views Asked by At

I'm reading a text on Version 6 unix, and just learned about inodes. I have the following question:

Suppose I have a file in one directory and a link to the file somewhere else. Am I correct to say that, if I delete the file, the inode will still exist because the refcount is not 0? And does this mean that the file isn't really deleted while the link exists, and I can access the file through the inode number?

2

There are 2 best solutions below

0
On BEST ANSWER

Yes, if the link is a hard link. No, if it's just a symbolic link.

A hard link is basically the same file being in more than one directory, with the same inode. Unlinking the file from one of its directories just reduces its reference count by one. It won't be deleted until it reaches zero.

A symbolic link has its own inode and redirects you to the other entry. A symbolic link will dangle if its target is removed. A symbolic link itself can be removed with no effect on the target file or directory.

0
On

File names are just entries in the directory tables pointing to somewhere in the disk. A hard link is just another name entry pointing to the same data. Any subsequent hard link is indistinguishable from the original file name entry.

So the answer is yes.