Linux and Unix rm command
rm [OPTION]... FILE...
rm removes each specified FILE. By default, it does not remove directories; see Removing Directories below for details.
The removal process unlinks a filename in a filesystem from data on the storage device, and marks that space as usable by future writes. In other words, removing files increases the amount of available space on your disk.
The data itself is not destroyed, but after being unlinked, it becomes inaccessible. Remove your files wisely! The effects of an rm operation cannot be undone.
Note: If what you want is to completely, unrecoverably erase the data on the disk, use the shred command instead. This will overwrite the file's contents so that they cannot be reconstructed later by any means.
When using rm, if the -I or --interactive=once option is given, and there are more than three files or the -r, -R, or --recursive are given, rm will prompt the user for whether to proceed with the entire operation. If the response is not yes, the entire command is aborted.
Otherwise, if a file is unwritable, standard input is a terminal, and the -f or --force option is not given, or the -i or --interactive=always option is given, rm prompts the user for whether to remove the file. If the response is not yes, the file is skipped.
|-f, --force||Ignore nonexistant files, and never prompt before removing.|
|-i||Prompt before every removal.|
|-I||Prompt once before removing more than three files, or when removing recursively. Less intrusive than -i, while still giving protection against most mistakes.|
|--interactive[=WHEN]||Prompt according to WHEN: never, once (-I), or always (-i). If WHEN is not specified, then prompt always.|
|--one-file-system||When removing a hierarchy recursively, skip any directory that is on a file system different from that of the corresponding command line argument|
|--no-preserve-root||Do not treat "/" (the root directory) in any special way.|
|--preserve-root||Do not remove "/" (the root directory). This is the default behavior.|
|-r, -R, --recursive||Remove directories and their contents recursively.|
|-v, --verbose||Verbose mode; explain at all times what is being done.|
|--help||Display a help message, and exit.|
|--version||Display version information, and exit.|
By default, rm does not remove directories. If the -r (--recursive) option is specified, however, rm will remove any matching directories and their contents.
Filenames Starting With A Dash
To remove a file whose name begins with a dash ("-"), you can specify a double dash ("--") separately before the filename. This is necessary so that rm does not misinterpret the filename as an option.
For instance, if there is a file in your current directory named "-file.txt", you can delete it with the command
rm -- -file.txt
Or, you can delete it by referring to it with a pathname. For instance, if the file "-file.txt" was located in the directory "/home/chope", you could delete it using:
...or, if /home/chope is your current directory,
...will work as well.
Remove the file myfile.txt. If the file is write-protected, you will be prompted to confirm that you really want to delete it.
rm -f myfile.txt
Remove the file myfile.txt. You will not be prompted, even if the file is write-protected; if rm can delete the file, it will.
Remove all files in the working directory. If it is write-protected, you will be prompted before rm removes it.
rm -f *
Remove all files in the working directory. rm will not prompt you for any reason before deleting them.
rm -i *
Attempt to remove every file in the working directory, but prompt before each file to confirm.
rm -I *
Remove every file in the working directory; prompt for confirmation if more than three files are being deleted.
rm -r mydirectory
Remove the directory mydirectory, and any files and directories it contains. If a file or directory that rm tries to delete is write-protected, you will be prompted to make sure that you really want to delete it.
rm -rf mydirectory
Same as the above command, but you will never be prompted; if rm can delete the files, it will.