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.

Stoic
  • 143
  • 4
  • possible duplicate of [Can I recover from "rm /*"?](http://serverfault.com/questions/77277/can-i-recover-from-rm) – jscott Jan 17 '11 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 '11 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. – Steve Folly Jan 18 '11 at 01:06
  • You may appreciate a new shell, like zsh, that warns when you type something with the destructive power of `rm *`. – Juliano Jan 18 '11 at 03:17

4 Answers4

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"

Jason Berg
  • 19,084
  • 6
  • 40
  • 55
  • 4
    Aliasing `rm` like that is a bad idea. What if you grow to depend on it and one day it's not there? – Dennis Williamson Jan 18 '11 at 00: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 '11 at 01:02
  • What if you grow to not depend on it and it's never, ever there the one time that you need it? – jgoldschrafe Jan 18 '11 at 04:12
  • Actually, a "rm -rf" overrides the -i option. So in many cases is not *that* useful as an alias. – Daniele Santi Jan 18 '11 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

Mark McKinstry
  • 935
  • 7
  • 5
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?

ewwhite
  • 197,159
  • 92
  • 443
  • 809
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.

Kenni
  • 66
  • 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 '11 at 23:52