How can I prevent accidental execution of the rm -r *command?
You could alias the rm
command to rm -i
in your shell, so it will ask your confirmation for each file.
However, some consider this to be harmful. See alias rm=“rm -i” considered harmful? on Superuser.com
Other thoughts are in How do I prevent accidental rm -rf /?* on StackOverflow.com.
The best advice is to grow to fear and respect the 'rm -r' or 'rm -rf' commands enough that, when you type them, you stop yourself and proceed slowly and with caution (reading over the command carefully a few times). The commands are useful and sometimes need to be used - but it's not a good idea to trick the system into saving you from this type of mistake; it's not a good idea to grow accustomed to such workarounds---consider building good habits that can be carried from machine to machine.