rm (Unix)

from Wikipedia, the free encyclopedia

rm (short for English remove , remove ' ) is in the Unix -World the usual command file - and directory entries delete / remove. The command is defined in the POSIX standard. It is a stand-alone program , not a Unix shell command.

Caution is advised when using rm , since by default there is no prompt to confirm the command; system-relevant files can be accidentally removed.

Files in Unix and derived file systems consist, on the one hand, of the actual data stock, the data object (the file content), to which a unique data node, a so-called inode , is assigned, and, on the other hand, of at least one reference ( English link ) to that inode, which is called " full “file name (ie including path) is represented. An inode can thereby multiple file names - that file object references ( English hard link ) - have.

In fact, the command rm ./pfad/dateinamedoes not delete the data object (the file contents) itself, but only removes the reference (hard link) to its inode from the directory tree of the file system.

If the last (hard) link to an inode is removed (and no more processes access the data), a file is considered deleted. In fact, only the corresponding data blocks are released for overwriting. As long as these data blocks have not been overwritten, a deleted file can therefore be restored.

The rm program can also be called without any problems if a process is still accessing the data. That person can continue to read the data without interference until it is terminated; only then are the blocks released.

rm and unlink

While the command rmis standardized by POSIX , unlinkthe second version of the Single UNIX Specification (SUSv2) is defined and has a smaller range of functions.

The specific functionality, i.e. whether the unlink system call is used, depends on the implementation used (this was the case with the original Unix variant ). As a rule, both commands, and , are now processed by the rm program . unlinkrmunlink

Secure deletion

The operating system only releases the data blocks after rm, but the data may still be physically stored for some time. Sensitive data (e.g. passwords or credit card numbers) should however no longer be readable. For safe deletion you have to open the file and overwrite all blocks. Some file systems also offer the option to immediately overwrite blocks that have become free. However, this takes time and is therefore only used in exceptional cases.

The widespread opinion that the data can still be restored with great effort after being overwritten once, for example through measurements with electron microscopes, is wrong, however; overwriting it once is completely sufficient; It is more important to remove all copies, including those made automatically during data backup.

See also: shred or wipe

File recovery

Unix does not normally support file recovery. Free data blocks may be immediately occupied by new data from other processes.

However, there are file systems that support recovery. Although there have been corresponding developments for a number of years, the “undelete” has not yet caught on.

syntax

rm [Optionen] Dateiname

Example:

rm test.txt

This example deletes the "test.txt" file from the directory in which you are currently located.

Options:

Three options rmare defined by POSIX :

-f
Force: No query if there is no write authorization and no error messages if file names do not exist, thus no change to the exit status.
-i
Interactive: Asks the user to confirm the deletion of each individual file.
-r
Recursive deletion: deletes a directory itself and all its contents, including all subdirectories and their contents.

Some implementations of the also rmoffer various additional options.

rm -rf /

The rm -rf /-Command is already used metaphorically by net culture because of its catastrophic effect , similar to / dev / null . Calling rmwith the parameters rand fto the root directory causes, as can already be seen from the syntax description , the recursive deletion of all files on the executing device (more precisely: on all integrated data carriers) without a query. If you execute this command as administrator (root), this leads in principle to the irrevocable deletion of the entire system; as a normal user, this usually only deletes all files that belong to the executing user (see Unix file rights for details on rights handling and file ownership ).

Sun Microsystems introduced " rm -rf /" protection with Solaris 10 (first version from 2005). When the Unix command is called , the program aborts with the error message that deleting is /not allowed. Shortly thereafter, the same feature was introduced in FreeBSD .

As required by the POSIX specification, the GNU version of also aborts rmwith an error message as long as the option --no-preserve-rootis not specified. This GNU-specific option and its counterpart --preserve-rootwere introduced in 2003 with the release of version 5.1.0 of the GNU Core Utilities , and with version 6.2 (released in 2006) the latter option became standard.

Individual evidence

  1. Nikolai Bezroukov: Creative uses of rm . Retrieved February 14, 2012.
  2. Secure deletion: overwrite once is sufficient . heise online , January 16, 2009
  3. a b c d rm . In: IEEE Std 1003.1-2008 . Open Group . Retrieved February 14, 2012.
  4. rm . In: FreeBSD Man Pages . FreeBSD Foundation. Retrieved February 14, 2012.
  5. rm invocation . In: GNU Coreutils . Free Software Foundation . Retrieved February 14, 2012.
  6. Meddling in the Affairs of Wizards ( Memento of the original from March 16, 2011 in the Internet Archive ) Info: The archive link was inserted automatically and has not yet been checked. Please check the original and archive link according to the instructions and then remove this notice. (English) @1@ 2Template: Webachiv / IABot / blogs.sun.com
  7. The Open Group Base Specifications Issue 7 - rm (English)
  8. Git commit support new options: --preserve-root and --no-preserve-root (English)
  9. Git commit ...-- preserve-root is now the default (English)