|
|
A UNIX filesystem stores files as an inode, a data structure used to locate the disk blocks belonging to the file. Directories associate filenames with inodes; a directory is a file containing a list of filenames and their corresponding inode numbers. When accessing a file, the system looks up its directory entry, obtains the inode number, and reads from or writes to the data stored in the disk blocks listed in the inode.
An inode may have more than one filename pointing to it; these filenames are called links. The inode keeps an internal count of the number of links pointing to it. rm zeroes out the inode number associated with the filename and reduces the link count in the inode by one. When the link count drops to zero, the system reclaims the inode and its disk blocks, destroying the file.
Removal of a filename requires write permission on its directory, but neither read nor write permission on the file itself because only the directory file is being modified. Directory files do not shrink when files are erased. If a file is a symbolic link, the link will be removed, but the file or directory to which it refers will not be deleted.
rm will not delete directories unless the -r option is used.
The following options are recognized:
If -f is not specified and the user does not have write permission on the target file, the user is prompted for confirmation. The file's name and permissions are printed and a line is read from the standard input. If that line begins with a ``y'' the file is deleted; otherwise it remains.
It is also forbidden to remove the root directory of a given file system.
If the ``sticky'' (t) bit is set on a directory, only the owner of a file can remove that file from the directory. See chmod(C) for more information about ``sticky'' bits.
ISO/IEC DIS 99452:1992, Information technology Portable Operating System Interface (POSIX) Part 2: Shell and Utilities (IEEE Std 1003.21992);
AT&T SVID Issue 2;
X/Open CAE Specification, Commands and Utilities, Issue 4, 1992.