Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I accidently did a rm * in the / directory in debian 6 while logged in as root. It didn't remove any of the directories, but I seems to have messed up something.

rm: cannot remove `132966': No such file or directory
rm: cannot remove `bin': Is a directory
rm: cannot remove `boot': Is a directory
rm: cannot remove `dev': Is a directory
rm: cannot remove `etc': Is a directory
rm: cannot remove `home': Is a directory
rm: cannot remove `lib': Is a directory
rm: cannot remove `lib32': Is a directory
rm: cannot remove `lost+found': Is a directory
rm: cannot remove `media': Is a directory
rm: cannot remove `mnt': Is a directory
rm: cannot remove `opt': Is a directory
rm: cannot remove `proc': Is a directory
rm: cannot remove `root': Is a directory
rm: cannot remove `sbin': Is a directory
rm: cannot remove `selinux': Is a directory
rm: cannot remove `srv': Is a directory
rm: cannot remove `sys': Is a directory
rm: cannot remove `tmp': Is a directory
rm: cannot remove `usr': Is a directory
rm: cannot remove `var': Is a directory

It's running websites and everything is still up. But I get this when trying to run any command.

root@host:/# dir
-bash: /bin/dir: No such file or directory
root@host:/# dir
-bash: /bin/dir: No such file or directory
root@host:/# dir
-bash: /bin/dir: No such file or directory
root@host:/# dir
-bash: /bin/dir: No such file or directory
root@host:/# dir
-bash: /bin/dir: No such file or directory
root@host:/# apt-get
-bash: /usr/bin/apt-get: No such file or directory

The bin directory still exists and dir is there. It just doesn't work for some reason.

I can't connect to the SSH anymore, but I'm already connected and it appears SCP can still access all directories but no command works.

What can I do? I've got a lot of stuff set up and I don't want to loose it. Is there any way to fix this?

edit: It appears I can still upload files to the server..

share|improve this question
3  
Just roll back to your latest daily or weekly backup image of course, duh! –  paradroid Feb 19 '12 at 19:36
1  
Also, dir? Shouldn't you be using ls? –  Camilo Martin Feb 20 '12 at 8:50
1  
And that is one of the #1 reasons why you don't log into your server as root. Next time be sure to add -rf into the rm command and then you'll really have some fun! –  kobaltz Mar 11 '12 at 16:15
add comment

migrated from stackoverflow.com Feb 19 '12 at 18:51

This question came from our site for professional and enthusiast programmers.

3 Answers

Take a bag of chips, a beer, turn on your favorite movie and watch it. After that you probably have cooled down and be ready to re-install your debian. And, if you don't want to get fat, just stop doing such mistakes in future.

share|improve this answer
    
Isn't there any solution? =( it has only removed the shortcuts lib64, initrd.img, vmlinuz –  Tike Feb 19 '12 at 17:16
    
You could set up another box and copy these things to the broken one. –  spidey Feb 19 '12 at 17:21
    
Ah well. Just ln lib64 to lib. This might fix most. The initrd.img and vmlinuz are not needed at runtime AFAIK because everything needed is loaded in RAM anyway. After that you might reinstall your kernel. –  spidey Feb 19 '12 at 17:27
    
I can't run any commands. I can rename stuff though (through scp), but it feels like a bad idea to rename lib to lib64. Or is it? –  Tike Feb 19 '12 at 17:31
    
Not rename, ln (link): ln -s /lib /lib64. I wonder if that works, though. –  spidey Feb 19 '12 at 17:47
show 1 more comment

This reminds me of a post I say about the same mistake. I cannot find the original link, but one is bellow. Some interesting points about it:

  • Once rm -rf / has been interrupted, system is still running as everything is still loaded in RAM. Do not do anything in a rush like exiting your shell, you might not be able to log again.
  • Now, what needs to be done is to find a way to restore what has been deleted. If you still have scp, or a running ftp/ssh server pointing to valid path, it might be easy; if you have lost /etc and most of your binaries, it might be hard.
  • Remember that you still have a shell, so you can use echo and redirections to create files. You can still cd in directories, and even read files with while read line; do echo $line; done < file. What you will probably miss is mkdir, and it is one of the first thing those VAX admin restore to be able to recreate /etc.

And this history can be found here.

Good luck.

Upade:

I found back the link of the full story: it is here.

share|improve this answer
add comment

If the scp is still alive, i could imagine to install the same version in a vm and copy all the lost files to the rm'ed machine. After all it will be easier to load the last nightly backup you made for sure?

share|improve this answer
add comment

Your Answer

 
discard

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