117 lines
4.2 KiB
HTML
117 lines
4.2 KiB
HTML
|
---
|
||
|
layout: page
|
||
|
category_title: File System
|
||
|
category-page: Manipulating
|
||
|
tags: directory list
|
||
|
author: Mattia Hijman
|
||
|
title: rm
|
||
|
previous-page: group-1/site/pages/fs/rm.html
|
||
|
---
|
||
|
<h1>Remove Command</h1>
|
||
|
<h>NAME</h>
|
||
|
|
||
|
<p>rm, unlink -- remove directory entries</p>
|
||
|
|
||
|
<h>SYNOPSIS</h>
|
||
|
|
||
|
rm [-dfiPRrvW] file ...
|
||
|
unlink file
|
||
|
|
||
|
<h>DESCRIPTION</h>
|
||
|
|
||
|
<p>The rm utility attempts to remove the non-directory type files specified on the command line.
|
||
|
If the permissions of the file do not permit writing, and the standard input device is a terminal,
|
||
|
the user is prompted (on the standard error output) for confirmation.</p>
|
||
|
|
||
|
<p>The options are as follows:</p>
|
||
|
|
||
|
<p>-d</p>
|
||
|
|
||
|
<p>Attempt to remove directories as well as other types of files.</p>
|
||
|
|
||
|
<p>-f</p>
|
||
|
|
||
|
<p>Attempt to remove the files without prompting for confirmation, regardless of the file's permissions.
|
||
|
If the file does not exist, do not display a diagnostic message or modify the exit status to reflect an error.
|
||
|
The -f option overrides any -i options.</p>
|
||
|
|
||
|
<p>-i</p>
|
||
|
|
||
|
<p>Request confirmation before attempting to remove each file, regardless of the file's permissions, or whether or not the standard input device is a terminal.
|
||
|
The -i option overrides any previous -f options.</p>
|
||
|
|
||
|
<p>-P</p>
|
||
|
|
||
|
<p>Overwrite regular files before deleting them.
|
||
|
Files are overwritten three times, first with the byte pattern 0xff, then 0x00, and then 0xff again, before they are deleted.</p>
|
||
|
|
||
|
<p>-R</p>
|
||
|
|
||
|
<p>Attempt to remove the file hierarchy rooted in each file argument.
|
||
|
The -R option implies the -d option. If the -i option is specified, the user is prompted for confirmation before each directory's contents are processed (as well as before the attempt is made to remove the directory).
|
||
|
If the user does not respond affirmatively, the file hierarchy rooted in that directory is skipped.</p>
|
||
|
|
||
|
<p>-r </p>
|
||
|
|
||
|
<p>Equivalent to -R.</p>
|
||
|
|
||
|
|
||
|
<p>-v</p>
|
||
|
|
||
|
<p>Be verbose when deleting files, showing them as they are removed.</p>
|
||
|
|
||
|
|
||
|
<p>-W</p>
|
||
|
|
||
|
<p>Attempt to undelete the named files.
|
||
|
Currently, this option can only be used to recover files covered by whiteouts.</p>
|
||
|
|
||
|
<p>The rm utility removes symbolic links, not the files referenced by the links.</p>
|
||
|
|
||
|
<p>It is an error to attempt to remove the files ``.'' or ``..''.</p>
|
||
|
|
||
|
<p>When the utility is called as unlink, only one argument, which must not be a directory, may be supplied.
|
||
|
No options may be supplied in this simple mode of operation, which performs an unlink(2) operation on the passed argument.</p>
|
||
|
|
||
|
<p>The rm utility exits 0 if all of the named files or file hierarchies were removed, or if the -f option was specified and all of the existing files or file hierarchies were removed.
|
||
|
If an error occurs, rm exits with a value >0.</p>
|
||
|
|
||
|
<h>NOTE</h>
|
||
|
|
||
|
<p>The rm command uses getopt(3) to parse its arguments, which allows it to accept the `--' option which will cause it to stop processing flag options at that point.
|
||
|
This will allow the removal of file names that begin with a dash (`-'). For example:</p>
|
||
|
<ul>
|
||
|
<li>rm -- -filename</li>
|
||
|
</ul>
|
||
|
<p>The same behavior can be obtained by using an absolute or relative path reference. For example:</p>
|
||
|
<ul>
|
||
|
<li>rm /home/user/-filename</li>
|
||
|
<li>rm ./-filename</li>
|
||
|
</ul>
|
||
|
<h>SEE ALSO</h>
|
||
|
|
||
|
<p>rmdir(1), undelete(2), unlink(2), fts(3), getopt(3), symlink(7)</p>
|
||
|
|
||
|
<h>BUGS</h>
|
||
|
|
||
|
<p>The -P option assumes that the underlying file system is a fixed-block file system.
|
||
|
In addition, only regular files are overwritten, other types of files are not.</p>
|
||
|
|
||
|
<h>COMPATIBILITY</h>
|
||
|
|
||
|
<p>The rm utility differs from historical implementations in that the -f option only masks attempts to remove non-existent files instead of masking a large variety of errors.
|
||
|
The -v option is non-standard and its use in scripts is not recommended.</p>
|
||
|
|
||
|
<p>Also, historical BSD implementations prompted on the standard output, not the standard error output.</p>
|
||
|
|
||
|
<h>STANDARDS</h>
|
||
|
|
||
|
<p>The rm command is almost IEEE Std 1003.2 (``POSIX.2'') compatible, except that POSIX requires rm to act like rmdir(1) when the file specified is a directory.
|
||
|
This implementation requires the -d option if such behavior is desired. This follows the historical behavior of rm with respect to directories.</p>
|
||
|
|
||
|
<p>The simplified unlink command conforms to Version 2 of the Single UNIX Specification (``SUSv2'').</p>
|
||
|
|
||
|
<h>HISTORY</h>
|
||
|
|
||
|
<p>A rm command appeared in Version 1 AT&T UNIX.</p>
|