2

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?

2
  • 1
    Read commands carefully before executing them, and never do administrative work without being on at least half a pot of coffee.
    – Mr_Spock
    May 26, 2013 at 11:23
  • Any way to make rm display a confirmation dialog for / (root) paths? May 26, 2013 at 11:30

1 Answer 1

7

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.

2
  • Thanks for the reply. I understand I should use as sudo less often as possible, but I constantly find myself having to remove/move/copy, or to build/compile stuff, or run bash scripts. Most of the time I require to use sudo - is this normal? Or is there a way to give my normal user more permissions? May 26, 2013 at 11:44
  • This really depends on what you're doing. If it's system-wide maintenance, then you can't really avoid running the majority of your commands as a privileged user. Compiling on the other hand shouldn't require elevated permissions. It's part of the *nix philosophy that the user should know what they're doing—no way to avoid that really, unless you constantly want to be prompted.
    – slhck
    May 26, 2013 at 11:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .