NewWork mode: your Claude Code or Codex on work calls, answering from your project's codeSkip to content
Middle1 view

Does a closed file have an inode? What is the difference between an open and a closed file when it is deleted?

Practice

Asked at

AI answer

Yes. A regular file on a filesystem has an inode whether or not it is currently open. The inode stores metadata and references to data blocks; the filename in a directory points to the inode.

Opening a file creates a file descriptor that refers to a file object in the kernel. close() closes only that descriptor and does not, by itself, delete the file. rm removes the filename from the directory (decrementing the number of hard links). If the file is still open, its data and inode usually remain accessible through open descriptors until the last one is closed; after that, the space is freed. That is why a deleted but open file can still occupy space and appear, for example, in lsof +L1.