Kids! Say no to rm -rf!

rm -rf is a bad habit, and it almost all cases an inappropriate command to use. The time saved not having to answer a few prompts is outweighed by the risk of accidentally deleting something important.

rm is the unix command to remove a file. When rm is told to delete a directory, it ignores it; -r instructs rm to instead delete everything in it, and then delete the directory itself. When rm encounters a file that is not writable (an important system file, for example), it prompts the user to make sure he really wants to delete it; -f instructs rm to instead delete the file without asking.

rm -r is the normal way to delete a directory (the equivalent of deltree in windows)

rm -f is to delete single files without being prompted. This is useful when being called from a script, for instance. It can be used to delete files matching a wildcard, but a safer way is to use chmod on the files that are actually supposed to be deleted (to make them writable) and then use rm <wildcard> to delete them.

rm -rf should be used never. To delete a whole directory with 'important' files in it, either use rm -r, and answer 'yes' to the files you really want to delete, or chmod these files beforehand. The prompt is there to protect you from doing something you didn't really mean to do; disable it at your peril.

As well as the obvious risk of deleting your unix operating system, there are some additional side-effects of unix's 'everything is a file' philosophy to consider:

When used on hardlinks to files, symbolic links to directories, and symbolic links to files, rm -r will just delete the link, not the actual file or directory. But, when used on a hardlink to a directory, it will descend and clean the directory out. rm -r will also traverse to mounted filesystems, including NFS and SMB network shares, giving you the potential to accidentally delete all the files on a data partition, or even a completely different computer. It is especially risky to use rm -r on a system with more than one account (or user) that has permissions to make hard linked directories, or mount drives - even if there was nothing risky last time you checked, another user may have hardlinked a directory or mounted a drive before rm is called.

The risks of this feature can be reduced by using rm -r instead of rm -rf, as rm -r will prompt before deleting important files. Marking files you value (MP3s, programs, documents, etc.) as read-only will protect them from rm -r, as will mounting foreign filesystems (FAT32, NTFS, SMB network drives, etc.) with read-only file permissions. Only read-only media can reliably protect your files from rm -rf.

Another good practice is to use the -v switch to make rm, mv, chmod, etc. tell you what they're doing, so that if they're not doing what you told them to do, you have the opportunity to stop them, and a log of what they've done.

It's far better to stop using rm -rf before you delete the entire filesystem of one or more computers than after.