3
Contributors
3
Replies
7
Views
5 Years
Discussion Span
Last Post by rubberman
1

To expand upon what 'cereal' said.

Linux identifies files/directories by their inode. This is the ONLY authoritative identifier for the component. That allows Linux to have hard links to a file, so even if one instance is deleted, the file itself is not until all links are removed. Also, when an application opens a file, that link count is increased, decreasing it when closed. When the link count to an inode (physical file) reaches zero, then, and ONLY then, will the file be physically deleted. This allows you to delete a file when some application is using it, which you cannot do in Windows. Once the application is done with the file, then the OS will remove it from storage.

So, consider the name/path of a file to only be a reference to the real file, which is identified by it's inode.

Just for your information (FYI), soft links do not increase the reference count to an inode, hence the occasional "missing link" with Linux.

-Rubberman

Votes + Comments
nice explanation
1

Just an aside, the C function to delete a file is unlink(filename) as is the REAL system shell program, which is unlink filename. IE, when you execute rm filename, in reality that is calling the 'unlink' program, or the unlink() function... Honestly, without looking at the 'rm' source code I'm not 100% certain which it uses. My best guess is that it uses the C function. :-)

The unlink() function as well as the unlink command just decrement the inode link count and remove the file from the current directory. Subsequent unlinks in the same directory will not do anything. This keeps you from issuing a gazillion unlinks to a file in one directory, causing the file to be physically deleted when it still has references from other directories or applications.

Edited by rubberman

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.