Running without backups means you have to be super careful to never make any mistakes. And hope your hardware never fails. (Even RAID can't save you from filesystem corruption caused by faulty RAM.) So that's your first problem. (Which I assume you've already realized and will be doing backups in the future.)
But there are things you can do to reduce the likelihood of mistakes like this:
rm='rm -I' to prompt if deleting more than 3 things.
- alias mv and cp to
mv -i and
cp -i (many normal use-cases for these don't involve overwriting a destination file).
sudo='sudo ' to do alias expansion on the first argument to
rm -I is a lot more useful than
rm -i. It usually don't prompt during normal use, so getting prompted when you didn't expect it is a lot more noticeable / better warning. With
-i (before I discovered
-I), I got used to typing
\rm to disable alias expansion, after being sure I'd typed the command correctly.
You don't want to get in the habit of relying on
rm -i or
-I aliases to save you. It's your safety line that you hope never gets used. If I actually want to interactively select which matches to delete, or I'm not sure if my glob might match some extra files, I manually type
rm -i .../*whatever*. (Also a good habit in case you're ever in an environment without your aliases).
Defend against fat-fingering Enter by typing
ls -d /*foo* first, then up-arrow and change that to
rm -r after you've finished typing. So the command line never contains
rm -rf ~/ or similar dangerous commands at any point. You only "arm" it by changing
rm with control-a, alt-d to go to the start of the line and adding the
-r or the
-f after you've finished typing the
~/some/sub/dir/ part of the command.
Depending on what you're deleting, actually run the
ls -d first, or not if that wouldn't add anything to what you see with tab-completion. You might start with
-rf) so it's just control-a / control-right (or alt+f) / space /
(Get used to bash/readline's powerful editing keybindings for moving around quickly, like control-arrows or alt+f/b to move by words, and killing whole words with alt+backspace or alt+d, or control-w. And control-u to kill to the beginning of the line. And control-/ to undo an edit if you go one step too far.
And of course up-arrow history that you can search with control-r / control-s.)
-rf unless you actually need it to silence prompts about removing read-only files.
Take extra time to think before pressing return on a
sudo command. Especially if you don't have full backups, or now would be a bad time to have to restore from them.