Check out safe-rm which is a wrapper for rm
that will allow you to set up a list of important directories that cannot be accidentally deleted.
This won't stop you from accidentally deleting files outside the listed directories, but it will prevent a catastrophe when your subconscious decides to up the ante and do an rm -rf /
.
That aside, the canonical way to prevent accidental deletion is to use alias rm="rm -i"
as mentioned in several of the other answers.
Extreme measures for extreme situations ...
If you're subconscious is as malicious as it sounds, it can still bypass this by using /bin/rm
instead to skip the alias. For some safeguard against this, create a file called -i
in the directories you work in often:
[me@home]$ touch -- -i
[me@home]$ ls
-i file1.txt file2.txt
When evil-you does /bin/rm -rf *
, the wildcard gets expanded to the list of files which starts with -i
and that will be seen as an option by /bin/rm
:
[me@home]$ /bin/rm -rf *
/bin/rm: remove regular empty file `file1.txt'?
(mouse-over the following block when your subconscious is not looking...)
Now let's hope your subconscious is not aware of the --
option...