DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

rm(C)


rm -- remove files or directories

Syntax

rm [ -firR ] file ...

Description

The rm command removes the entries for one or more files from a directory.

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:


-f
When invoked with the -f option rm does not prompt the user for confirmation for files on which the user does not have write permission. The files are simply removed. Any previous occurrences of the -i option on the command line are ignored. This option only applies if rm is invoked with its standard input attached to a terminal.

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.


-i
The -i (interactive) option causes rm to ask whether to delete each file, and if the -r or -R option is in effect, whether to examine each directory. Any previous occurrences of -f are ignored.

-r
The -r (recursive) option causes rm to recursively delete the entire contents of the any directories specified, and the directories themselves. Symbolic links encountered with this option will not be traversed. Note that the rmdir(C) command is a safer way of removing directories.

-R
Equivalent to -r.
The special option ``--'' can be used to delimit options. For example, a file named ``-f'' could not be removed by rm because the hyphen is interpreted as an option; the command rm -f would do nothing, since no file is specified. Using rm -- -f removes the file successfully.

Exit values

rm returns the following values:

0
successful completion

>0
an error occurred

Limitations

It is forbidden to remove the file .. to avoid the consequences of inadvertently doing something like:

rm -r .*

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.

See also

chmod(C), rmdir(C)

Standards conformance

rm is conformant with:

ISO/IEC DIS 9945-2:1992, Information technology - Portable Operating System Interface (POSIX) - Part 2: Shell and Utilities (IEEE Std 1003.2-1992);
AT&T SVID Issue 2;
X/Open CAE Specification, Commands and Utilities, Issue 4, 1992.

Notices

A version of rm that can handle files greater than 2GB is available in /u95/bin. See rm(1) for more information.
© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 03 June 2005