Rm (Unix)
- The title given to this article is incorrect due to technical limitations. The correct title is rm (Unix).
de:rm
The rm command in the Unix operating system is used to remove files from the file system. It is similar to the del command in DOS.
Its usage is considered potentially more dangerous than equivalents in other operating systems because of the way Unix and Unix-like systems parse wildcards and names of special directories and in its non-verbose actions. A classic example, which deletes all files in a directory instead of the files intended:
$ rm * .o rm: cannot remove `.o': No such file or directory
Options
- -d, --directory
- unlink FILE, even if it is a non-empty directory (super-user only)
- -f, --force
- ignore nonexistent files, never prompt
- -i, --interactive
- prompt before any removal
- -r, -R, --recursive
- remove the contents of directories recursively
- -v, --verbose
- explain what is being done
- --help
- display help and exit
- --version
- output version information and exit
To remove a file whose name starts with a `-', for example `-foo', use one of these commands:
rm -- -foo
rm ./-foo
Note that if you use rm to remove a file, it is usually possible to recover the contents of that file since rm does not remove it from the Hard disk. it simply removes the filesystems link to it. If you want more assurance that the contents are truly unrecoverable, consider using shred.
In practice, to allow for the recovery of rm'd files, don't use rm itself. Create an alias such as remove which moves the files to a local "trash" file so you can go there and recover files you accidentally removed.