Today, using sudo -s
, I wanted to rm -R ./lib/
, but I actually rm -R /lib/
.
I had to reinstall my OS (Mint 15) and re-download and re-configure all my packages. Not fun.
How can I avoid similar mistakes in the future?
Today, using sudo -s
, I wanted to rm -R ./lib/
, but I actually rm -R /lib/
.
I had to reinstall my OS (Mint 15) and re-download and re-configure all my packages. Not fun.
How can I avoid similar mistakes in the future?
First of all, stop executing everything as root. You never really need to do this. Only run individual commands with sudo
if you need to. If a normal command doesn't work without sudo, just call sudo !!
to execute it again.
If you're paranoid about rm
, mv
and other operations while running as root, you can add the following aliases to your shell's configuration file:
[ $UID = 0 ] && \
alias rm='rm -i' && \
alias mv='mv -i' && \
alias cp='cp -i'
These will all prompt you for confirmation (-i
) before removing a file or overwriting an existing file, respectively, but only if you're root
(the user with ID 0).
Don't get too used to that though. If you ever find yourself working on a system that doesn't prompt you for everything, you might end up deleting stuff without noticing it. The best way to avoid mistakes is to never run as root and think about what exactly you're doing when you use sudo
.