View previous topic :: View next topic |
Author |
Message |
Chaosite Guru
Joined: 13 Dec 2003 Posts: 540 Location: Right over here.
|
Posted: Sat Jul 08, 2006 2:20 pm Post subject: TIP: Recover from "rm -rf /" |
|
|
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 .
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 |
|
|
ld50 Tux's lil' helper
Joined: 13 Feb 2005 Posts: 135
|
Posted: Sat Jul 08, 2006 3:00 pm Post subject: |
|
|
Nice to know that.
Here's another tip:
make a file called -i in /
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 |
|
|
bobwhoops n00b
Joined: 09 Jan 2005 Posts: 56
|
Posted: Sat Jul 08, 2006 7:26 pm Post subject: |
|
|
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 |
|
|
ld50 Tux's lil' helper
Joined: 13 Feb 2005 Posts: 135
|
Posted: Sat Jul 08, 2006 8:05 pm Post subject: |
|
|
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 |
|
Back to top |
|
|
suicidal_orange_II Apprentice
Joined: 04 Sep 2004 Posts: 299
|
Posted: Sun Jul 09, 2006 11:39 pm Post subject: |
|
|
You'd be suprised - I have never done "rm -rf /" but I did manage an "cat /dev/urandom > /dev/hda" once
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 |
|
|
truc Advocate
Joined: 25 Jul 2005 Posts: 3199
|
Posted: Mon Jul 10, 2006 10:52 am Post subject: Re: TIP: Recover from "rm -rf /" |
|
|
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 |
|
|
v7n Guru
Joined: 24 Jan 2006 Posts: 352
|
Posted: Mon Jul 10, 2006 12:01 pm Post subject: |
|
|
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' _________________ /~x86 /*-sources /oss /zsh /urxvt /vim /openbox /rox /xmms /Opera |
|
Back to top |
|
|
nesl247 Veteran
Joined: 15 Jun 2004 Posts: 1614 Location: Florida
|
Posted: Mon Jul 10, 2006 6:36 pm Post subject: |
|
|
ld50 wrote: | Nice to know that.
Here's another tip:
make a file called -i in /
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 |
|
|
opentaka l33t
Joined: 18 Feb 2005 Posts: 840 Location: Japan
|
Posted: Tue Jul 18, 2006 9:19 pm Post subject: |
|
|
the worst thing I did was 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 |
|
|
|