*** Welcome to piglix ***

Rm (Unix)


rm (short for remove) is a basic UNIX command used to remove objects such as files, directories, device nodes, symbolic links, and so on from the filesystem. To be more precise, rm removes references to objects from the filesystem, where those objects might have had multiple references (for example, a file with two different names), and the objects themselves are discarded only when all references have been removed and no programs still have open handles to the objects.

This allows for scenarios where a program can open a file, immediately remove it from the filesystem, and then use it for temporary space, knowing that the file's space will be reclaimed after the program exits, even if it exits by crashing.

rm generally does not destroy file data, since its purpose is really merely to unlink references, and the filesystem space freed may still contain leftover data from the removed file. This can be a security concern in some cases, and hardened versions sometimes provide for wiping out the data as the last link is being cut, and programs such as shred are available which specifically provide data wiping capability.

To remove a file named "foo" from a directory one could type:

Normally, no output is produced by rm, since it typically only generates messages in the event of an error. The -v option can be used to get rm to detail successful removal actions.

Users concerned about removing files unexpectedly - particularly when using wildcards - sometimes use the -i option to cause rm to verify each removal in advance, although this method may be inconvenient for use on large numbers of files.

rm is generally only seen on UNIX-derived operating systems, which typically do not provide for recovery of deleted files through a mechanism like the recycle bin, hence the tendency for users to enclose rm in some kind of wrapper to limit accidental file deletion.

There are undelete utilities that will attempt to reconstruct the index and can bring the file back if the parts were not reused.

Common options that rm accepts include:

rm can be overlain by a C shell alias or Bourne shell function of "rm -i" so as to avoid accidental deletion of files. If a user still wishes to delete a large number of files without confirmation, they can manually cancel out the -i argument by adding the -f option (as the option specified later on the expanded command line "rm -i -f" takes precedence). Unfortunately this approach generates dangerous habits towards the use of wildcarding, leading to its own version of accidental removals.


...
Wikipedia

...