Skip to content
Advertisement

What really happens when deleting file [closed]

Let’s say that I created a file. A new inode has created. Then I created a soft link to that file, and deleted the hard link.

Does the inode still exist? Does it point to the same location in the memory? Is the soft link connected to the inode that is connected to the memory, and that’s the reason for not finding the file, or does the soft link lose its connection to the inode?

Thank you.

Advertisement

Answer

This is offtopic and more than one question, but:

A softlink in Linux is not connected to an inode. It only have the name of the file (see the size of the softlink? it is the length of the name is links to!). Even renaming the original will break the link.

[bart@localhost link]$ touch foo
[bart@localhost link]$ ln -s foo bar
[bart@localhost link]$ ls -la
lrwxrwxrwx   1 bart bart    3 Dec 13 21:09 bar -> foo
-rw-rw-r--   1 bart bart    0 Dec 13 21:09 foo
[bart@localhost link]$ mv foo foo2
[bart@localhost link]$ ls -la
lrwxrwxrwx   1 bart bart    3 Dec 13 21:09 bar -> foo
-rw-rw-r--   1 bart bart    0 Dec 13 21:09 foo2
[bart@localhost link]$ cat bar
cat: bar: No such file or directory

An inode is gone if you delete a file.

Advertisement