Introduction
This page describes how to delete files through terminal.
It is possible, though difficult, to recover files deleted through rm. See DataRecovery. If you want to permanently delete a file use shred.
Commands for deleting files
The terminal command for deleting file(s) is rm. The general format of this command is rm [-f|i|I|q|R|r|v] file...
rm removes a file if you specify a correct path for it and if you don't, then it displays an error message and move on to the next file. Sometimes you may not have the write permissions for a file, in that case it asks you for confirmation. Type yes if you want to delete it.
Options
-f - deletes read-only files immediately without any confirmation.If both -f and -i are used then the one which appears last in the terminal is used by rm.
-i - prompts for confirmation before deleting every file beforing entering a sub-directory if used with -R or -r. If both -f and -i are used then the one which appears last in the terminal is used by rm.
-q - suppresses all the warning messages however error messages are still displayed. However the exit status is modified in case of any errors.
-R - means delete recursively and is used to delete the directory tree starting at the directory specified i.e. it deletes the specified directory along with its sub-directory and files.
-r - same as -R.
-v - displays the file names on the output as they are being processed.
-I - prompts everytime when an attempt is made to delete for than 3 files at a time or while removing recursively.
Precautions
These precautions are to help you avoid dangerous commands. You should not execute them!
Never type sudo rm -R / or sudo rm -r / as it deletes all the data in the root directory and will delete the data of all the mounted volumes until you want to wipe of everything from your system.
sudo rm -f /* also does blunders with your system.