4

I was trying to remove a directory on my server when I unintentionally ran the following command (notice the space) as root

rm -rf db /*

can someone tell me, in what ways this must have impacted my server, since I can see I can no longer access some of the sites on my server.
I am getting a 500 error on these sites.

Any help is appreciated.

4
  • possible duplicate of Can I recover from "rm /*"?
    – jscott
    Jan 17, 2011 at 23:54
  • 5
    There are many other dupes of this on SF. @Jason Berg is correct, reinstall and restore from backup. Tough lesson to learn, but hey, that's what backups are for.
    – jscott
    Jan 17, 2011 at 23:56
  • Ouch. My advice would be to use ls first to see what would be deleted with the appropriate wildcard(s). When you're satisfied they are the files to be deleted, replace ls with your most evil rm -rf command. Jan 18, 2011 at 1:06
  • You may appreciate a new shell, like zsh, that warns when you type something with the destructive power of rm *.
    – Juliano
    Jan 18, 2011 at 3:17

4 Answers 4

8

Wow...Sorry...that's bad. You just deleted pretty much everything on your server. Time to reinstall and restore from backups.

In the future, you might want to put this little line in your bashrc and stop running as root on your server:

alias rm="rm -i"

4
  • 4
    Aliasing rm like that is a bad idea. What if you grow to depend on it and one day it's not there? Jan 18, 2011 at 0:57
  • 1
    Well...I would say it's a safety net. You don't want to depend on a safety net but you're glad it's there when you need it. Just because you may work somewhere without a safety net doesn't mean you should never put one up.
    – Jason Berg
    Jan 18, 2011 at 1:02
  • What if you grow to not depend on it and it's never, ever there the one time that you need it? Jan 18, 2011 at 4:12
  • Actually, a "rm -rf" overrides the -i option. So in many cases is not that useful as an alias. Jan 18, 2011 at 12:25
4

Like Jason Berg said, your're mostly screwed.

You should use this alias to prevent this from happening:

alias rm="rm --preserve-root"

You can recover some files if any running processes have them open: http://www.linux.com/archive/feed/58142

1
  • --preserve-root only works for preventing rm -rf /, not rm -rf /*. It wouldn't have helped here. Jan 18, 2011 at 4:13
0

Don't do that. You've potentially lost files in the root directory level of the server, starting alphabetically with /bin, /boot, dev... Did you allow the command to run in its entirety or did you Ctrl-C to stop it?

0
0

I suppose you realized the problem and cancelled the command? (since you're saying that some of your sites are still alive). You deleted everything in / probably in alphabetically order, until the point where you cancelled the command.

If you just type

ls -l /

do you then have /bin and /boot? I would expect these to get deleted first.

1
  • yeah. I cancelled the command. however, i am no longer able to access server via SSH, which probably means the above folders have long gone.
    – Stoic
    Jan 17, 2011 at 23:52

You must log in to answer this question.

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