Unlink
Unlink is the removal of a directory entry naming a file; POSIX semantics preserve existing open references, while network-filesystem behavior requires additional qualification.
Linux unlink() removes a name; if that was the last hard link, existing open references can keep the file usable after its pathname disappears. Reclamation depends on releasing the remaining references, not merely removing one pathname. A symbolic-link argument removes the symbolic link itself, not its target. Plain unlink() does not remove directories; unlinkat() with AT_REMOVEDIR requests directory removal instead. Namespace removal is not secure erasure or proof of crash-persistent deletion. On ext4, orphan recovery completes pending reclamation after a crash; it does not establish whether an application's namespace change was durably synchronized. [5] [3] Removing and recreating a coordination-file name can let participants lock different files; a persistent name is part of the locking protocol, not disposable cleanup. [6] NFS requires a separate scope check: the Linux unlink manual documents active silly-renamed files as a possible EBUSY cause and warns about loss of access to files still in use. [1] See the NFS records for conditional server preservation. [7]
Relations
- related
- Inode, Hard link, Atomic rename, Open file description, Directory fsync, Ext4 orphan inode, Ext4 orphan file, Advisory file lock, NFS silly rename, NFS open-file preservation, Whiteout, Link count, Sticky bit
Advantages
- Allows a name to be removed without interrupting existing users of the open file.
Limitations
- Other hard links and open references can preserve the file after the name is removed.
- Does not promise physical erasure or persistent deletion after a crash.
- Do not assume all NFS clients and servers preserve every remote open reference when a name is removed.
Citations
- Linux man-pages 6.19: unlink(2)
- Linux man-pages 6.19: fsync(2)
- Linux v6.12: ext4 orphan inode handling
- Hesela: A lock follows the opened file, not the replacement name
- Why deleted NFS files become .nfs files