Introduction to UNIX for Web Developers Deleting Files The "rm" utility is used to delete files. As a warning, in UNIX there is no easy way to recover a deleted file unless you have it saved in a backup. So be very careful when using this command.

rm follows the standard form of:

rm [options] space_delimted_filelist

The rm utility has three extremely useful options

Option Explanation
-r Deletes in a recursive manner including whole directories. Obviously you should be extremely careful with this option.
-i Specifies that you wish to reconfirm each file before it is deleted. This is a particularly useful option if you are deleting using -r or with wild cards.
-f Bypasses the prompt when deleting against permission.
-- Specifies that the options are over if necessary

[rm Example]

It cannot be said too forcefully that you should be extremely careful when using wildcards with "rm". in particular, you should try not to use the rm utility like "rm *' or "rm -r *" unless you really, really, really know what you are doing AND you have already backed up the data you are deleting. If you delete files by mistake, and you have not made your own backup, your own recourse is to hope that your system administrator has backed up the system for you.

One deeply evil mistake is when you mean to type "rm *.bak" and instead you type "rm * .bak". Notice the accidental space between the "*" and the ".bak". If you do this, all your files will be erased and you will get an error message saying that the file .bak does not exist. Believe me, this is easy to do...I have done it twice to my great dismay. So be very careful. It is always safer to use the "-i" option when you use rm's with wild cards.

Previous | Next | Table of Contents