Pergunta

I am wondering how the internal mechanism of file deletion works on Unix.

If there are some hard links pointing to an actual file, do I need to delete all links in order to delete the file?

If I delete the file, will the hard links be destroyed or deleted automatically?

On the other hand, if I use symbolic links to point to a file what should be done to delete the file?

Finally, the space of the file will be free for another use when all links pointing to it are destroyed. Is that correct?

Foi útil?

Solução

A "file" has some content and one or more hard links to this data, ie. one or more "path+filename". If there is a file with multiple file names, in order to delete the content, you need to delete all hard links,
ie. all file names of it.
You can´t delete the file as in file content directly, you can only delete hard links.
If all links to the content are destroyed, the content itself will be deleted (at least marked as free space)

Symlinks: Deleting a symlink does not delete the file content
nor the actual hard link which the symlink is pointing to

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top