Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
TIP: Recover from "rm -rf /"
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
Chaosite
Guru
Guru


Joined: 13 Dec 2003
Posts: 540
Location: Right over here.

PostPosted: Sat Jul 08, 2006 2:20 pm    Post subject: TIP: Recover from "rm -rf /" Reply with quote

Recently, I was trying to save some space, and was going to do rm -rf *. However, since "*" is very close to "/" on the numpad, I managed to start forcibly and recursively removing my entire system =(

Of course, I hit Ctrl+C as fast as my reflexes would allow, and surveyed the damage, to find out I lost /sbin. As you probably know, you don't really need /sbin - unless you plan to reboot, automount partitions, and other neat things :P.

Anyway, the first thing you must remember is that portage knows which files belong to which package. Therefore, you can recover /sbin. You're a bit out of luck if its /home or /etc you lost, but you have backups (of at least /home), right?

Tto get the list of packages, you need to use equery.
Code:
# equery belongs -f ^/sbin


If you redirect it to a file, it gives you more usable output.
Code:
# equery belongs -f ^/sbin > missingPackages


Add a = at the start of each entry:
Code:
# sed -ie 's/^/=/' missingPackages


Then you pass it on to emerge.
Code:
# xargs emerge < missingPackages


And hopefully, you've got the directory back. This won't work for every directory, though - you need /lib, /bin, and /usr, and /etc... And you can't do anything for /home. Worked for me, though. =)
Back to top
View user's profile Send private message
ld50
Tux's lil' helper
Tux's lil' helper


Joined: 13 Feb 2005
Posts: 135

PostPosted: Sat Jul 08, 2006 3:00 pm    Post subject: Reply with quote

Nice to know that.

Here's another tip:

make a file called -i in /

Code:

cd /
touch -- -i


then, when you do a rm -rf *, the file -i will act as the -i option, so it will prompt you if you want to delete everything

example:
Code:


 ~ $ mkdir test
 ~ $ cd test
 ~/test $ touch -- -i
 ~/test $ touch important_file
 ~/test $ mkdir important_dir
 ~/test $ ls
-i  important_dir  important_file
 ~/test $ rm -rf *
rm: remove directory `important_dir'?
Back to top
View user's profile Send private message
bobwhoops
n00b
n00b


Joined: 09 Jan 2005
Posts: 56

PostPosted: Sat Jul 08, 2006 7:26 pm    Post subject: Reply with quote

eric@karp:~% rm *
zsh: sure you want to delete all the files in /home/eric [yn]?


It doesn't stop `rm -rf /` though.
Back to top
View user's profile Send private message
ld50
Tux's lil' helper
Tux's lil' helper


Joined: 13 Feb 2005
Posts: 135

PostPosted: Sat Jul 08, 2006 8:05 pm    Post subject: Reply with quote

Code:

It doesn't stop `rm -rf /` though.


It only works when you have a * wildcard.

Also, nobody is going to rm -rf / by mistake :D
Back to top
View user's profile Send private message
suicidal_orange_II
Apprentice
Apprentice


Joined: 04 Sep 2004
Posts: 299

PostPosted: Sun Jul 09, 2006 11:39 pm    Post subject: Reply with quote

You'd be suprised - I have never done "rm -rf /" but I did manage an "cat /dev/urandom > /dev/hda" once :oops:

Luckily the first partition was swap, and when that got wiped the box crashed. Nice to know there is a way back from such mistakes :)


Suicidal_Orange
Back to top
View user's profile Send private message
truc
Advocate
Advocate


Joined: 25 Jul 2005
Posts: 3199

PostPosted: Mon Jul 10, 2006 10:52 am    Post subject: Re: TIP: Recover from "rm -rf /" Reply with quote

Chaosite wrote:

Then you pass it on to emerge.
Code:
# xargs emerge < missingPackages


I think you should also add the --oneshot option to the emerge, otherwise it can pollute your world file :?:
Back to top
View user's profile Send private message
v7n
Guru
Guru


Joined: 24 Jan 2006
Posts: 352

PostPosted: Mon Jul 10, 2006 12:01 pm    Post subject: Reply with quote

Quote:
Recently, I was trying to save some space, and was going to do rm -rf *. However, since "*" is very close to "/" on the numpad, I managed to start forcibly and recursively removing my entire system =(
That's way you have to use '*' between '7' and '9' :twisted:
_________________
/~x86 /*-sources /oss /zsh /urxvt /vim /openbox /rox /xmms /Opera
Back to top
View user's profile Send private message
nesl247
Veteran
Veteran


Joined: 15 Jun 2004
Posts: 1614
Location: Florida

PostPosted: Mon Jul 10, 2006 6:36 pm    Post subject: Reply with quote

ld50 wrote:
Nice to know that.

Here's another tip:

make a file called -i in /

Code:

cd /
touch -- -i


then, when you do a rm -rf *, the file -i will act as the -i option, so it will prompt you if you want to delete everything

example:
Code:


 ~ $ mkdir test
 ~ $ cd test
 ~/test $ touch -- -i
 ~/test $ touch important_file
 ~/test $ mkdir important_dir
 ~/test $ ls
-i  important_dir  important_file
 ~/test $ rm -rf *
rm: remove directory `important_dir'?


Easier way is to add "alias rm='rm -i'" to your .bashrc.
Back to top
View user's profile Send private message
opentaka
l33t
l33t


Joined: 18 Feb 2005
Posts: 840
Location: Japan

PostPosted: Tue Jul 18, 2006 9:19 pm    Post subject: Reply with quote

the worst thing I did was
Code:
mkreiserfs
ing the wrong partition and never noticing that :(
added
Code:
 alias rm -rf /='emerge --info'

to .bash_profile :)
_________________
"Being defeated is often a temporary condition. Giving up is what makes it permanent" - Marilyn vos Savant
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum