A really, really sad experience. Due to a variable not set correctly in a script the command there “rm $INSTALLDIR/* -R” started at / .. a really nightmare. 3 things I learned

  1. Always having a backup. Fortunately I had one 14 days old .. but only by a fluke. My digital live could be restored so far ..
  2. Never use such a command with some security checks wrapped around. So far I added some code
    if [ ! $INSTALLDIR = "" ] && [ ! $INSTALLDIR = "/" ] && [ ! $INSTALLDIR = "/home" ] && [ ! $INSTALLDIR = "/home/$USERNAME" ]; then
    echo “rm $INSTALLDIR/* -R”
    rm $INSTALLDIR/* -R
    fi
  3. Keep cool if such a shit happened. There is in between a possibility to get data back from ext3 partitions with an excellent tool ext3grep.

Backup and ext3grep has made me happy again. If anyone has some additional hints avoiding such a nightmare when executing a script feel free.


2 Comments on “Using “rm * -R” in a script”

You can track this conversation through its atom feed.

  1. Graham White says:

    Wow, that was bad coding. You’ll definitely only make that mistake once though.

    I’m not sure what your script is trying to do but your current checks aren’t safe either really. I’d always want to be doing “rm -rf /somewhere/” in my script. You could consider the -z option to test for the empty string too.

  2. catshout says:

    Yeah, sometimes one made a mistake but only the one is a jerk who make same mistake twice :-)

    Thanks for comments, I know that the validation can’t secure everything; so I’ve thought about some “jail” like chroot or similar for the development environment.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>