Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Hey Guys,
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.

share|improve this question
    
possible duplicate of 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 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 '11 at 3:17

4 Answers 4

up vote 8 down vote accepted

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"

share|improve this answer
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 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 '11 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? –  jgoldschrafe Jan 18 '11 at 4:12
    
Actually, a "rm -rf" overrides the -i option. So in many cases is not that useful as an alias. –  Mr Shunz Jan 18 '11 at 12:25

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

share|improve this answer
    
--preserve-root only works for preventing rm -rf /, not rm -rf /*. It wouldn't have helped here. –  jgoldschrafe Jan 18 '11 at 4:13

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?

share|improve this answer

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.

share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.