What is meant by "In Linux, the name of a file is not inherent to the file."

I don't quite understand

Recommended Answers

All 3 Replies

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.


commented: nice explanation +9

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.