Rm (short for "remove" ) is the standard in the UNIX world command to delete files and directory trees. Unlike other operating systems, such as MS -DOS, the delete command in UNIX is implemented as an independent program and not in the command line interpreter. Supposedly safe handling of rm may suddenly withdraw its foundation the entire system.
Rm and unlink
Strictly speaking, the rm command does not delete a file on Unix. The Unix file system distinguishes between data, which are described by an inode, and path names that point to directories within the inodes. An inode can have multiple path names, which is called in the Unix terminology (hard) link.
Rm internally calls for non - directory files the system call unlink on which removes such a link and the associated path name. The inode and the data blocks are but not released until
This means that you can also call then rm problems when a process accesses the data. This can read the data without disruption to the end. Was it the last link and process the data when the file is closed by the process are freed automatically by the operating system.
The unlink command always uses the system call unlink and therefore when he was called by a privileged user may also delete non-empty directories.
The operating system is free to RM, only the blocks of data, but the data remain stored for some time under physical conditions. Sensitive data (eg passwords and credit card numbers) should, however, can no longer be read. To securely erase one must therefore open the file and overwrite all blocks. Also, some file systems offer the option to override which blocks immediately. However, this takes time and is therefore used only in exceptional cases.
However, the widespread opinion, let that data after a single overwrite even with great effort, for example by measurements using electron microscopes to restore is wrong; a simple overwriting is perfectly adequate; to eliminate all copies and automatically generated backups is important.
See also: shred or wipe
Unix does not normally support the recovery of files. That has become free data blocks are immediately occupied under circumstances of new data from other processes.
However, there are file systems that support a recovery. Although there are similar developments for several years, the " undelete " has not been enforced.
Rm [options ] filename example:
Rm test.txt This example deletes the file " test.txt " from the directory where you are.
Three options of rm are defined in POSIX:
Some implementations of rm offer several additional options beyond.
Rm- rf /
The rm- rf / command is already used metaphorically because of its disastrous effects of the Internet culture, similar to / dev / null. R and f to the root directory (root ) causes the invocation of rm with the parameters, as you can see the syntax description already, the recursive delete all files on the computer running (more precisely, on all mounted disks ) without question. Performs to this command as root, the principle leads to irrevocable deletion of the entire system; as a normal user, this deletes all the files that belong to the user running the program (see Unix file permissions for details of rights of use and ownership of files) in the rule.
Sun Microsystems introduced a " rm- rf / " protection with a Solaris 10 (first release 2005). When calling the said Unix commands, the program aborts with an error message that the deletion of / is not allowed. Shortly after, the same function in FreeBSD was introduced.
As required by the POSIX specification, also breaks the GNU version of rm with an error message unless the option - no- preserve- root is specified. This GNU -specific option and its counterpart - preserve- root were introduced in 2003 with the release of version 5.1.0 of the GNU core utilities, and with version 6.2 ( published in 2006 ) was the latter option standard.