I just ran rm /* accidentally, any fix?

8

1

I fell so stupid...

I just ran rm /* accidentally, but I meant rm ./* on a cloud server with root access.

Now, no one command works. ls, ssh, sftp... none.

Is there a way to fix that? (Note: params like -r or -f are no used in this case).

mateussouzaweb

Posted 2013-02-18T20:44:48.737

Reputation: 85

19Yes, restore last backup... – Gilles Quenot – 2013-02-18T20:46:11.200

5And after restoring, alias rm to rm -i, at least for a while :-) – jaume – 2013-02-18T22:56:54.863

2Also, if deleting all the files in the current directory is something you do often, get in the habit of saying rm * –– the ./ is totally unnecessary and, as you’ve experienced, can lead you into trouble. – Scott – 2013-02-18T23:43:14.357

3Just because you did something stupid doesn't make the question less valuable. +1 from me. – 0xC0000022L – 2013-02-19T00:44:12.943

ls before rm. – LawrenceC – 2013-02-19T00:45:46.873

@sputnick - curious why you put that as a comment instead of an answer, especially considering what the accepted answer was...? – aidan – 2013-02-19T06:25:50.387

http://www.lug.wsu.edu/node/414 – Dan is Fiddling by Firelight – 2013-02-19T06:30:42.767

if you didn't put -r rm should have not descended into subdirectories so probably it would have not deleted anything as all things in / are (usually) folders (except maybe a vmlinuz and initrd symlinks). Do you have a file or folder named -rf in your /? – Carlos Campderrós – 2013-02-19T08:50:00.890

@jaume No, don't alias…just get in the habit of doing it. That way, you won't become reliant on it, and you'll automatically do it on other systems, too. – Blacklight Shining – 2013-10-22T12:34:15.967

Get in the habit of not using root unless you really need to. Most things can be done from a regular account with sudo access. – Blacklight Shining – 2013-10-22T12:35:22.390

@BlacklightShining One thing does not rule out the other, the OP can set the alias while getting into the habit of using rm -i, since rm -i -i <file> works just fine. The alias is a safety net. The alias can be temporary disabled by prefixing the command with a backslash like \rm <file> or quoting it: "rm" <file>. – jaume – 2013-10-29T08:46:48.000

Answers

15

Restore from backup.

Depending on the filesystem you may be able to run an undelete or recovery utility, but it's likely easier and more reliable to just restore from a backup.

LawrenceC

Posted 2013-02-18T20:44:48.737

Reputation: 63 487

5

Backup is likely your best fix, however if that isn't an option for whatever reason there are some techniques that can help recover deleted files from ext3/4 partitions.

For any of these methods to be effective you want to drop to single user mode and unmount the disk(s) as soon as possible. And preferably run these from a livecd or other recovery environment is also a significantly safer method to avoiding accidental data loss while trying to recover your data.

I won't post an epic on undelete processes as you should try to use the backups first, here are the links I find most helpful.

Techdragon

Posted 2013-02-18T20:44:48.737

Reputation: 161

Of course you need to be able to stop using and unmount the affected volume as soon as possible if you want to go this route. – dmckee --- ex-moderator kitten – 2013-02-19T02:22:17.530

@dmckee your totally right, Should have mentioned it. (adds warning line) – Techdragon – 2013-02-19T02:47:52.570

4

If the rm didn't eat too much (when it happened to me, I killed it when it was halfway through /bin...), you can start the machine in rescue mode, check what packages are affected (in rpm's case, rpm -Va tells you), and reinstall those.

Be advised that this only works on new moon, after midnight. A short rain dance beforehand might be beneficial. Or not. YMMV.

(Yes, this is Unix' brutal way of teaching unsuspecting users to consider each command carefully before pressing ENTER. Consider yourself taught.)

vonbrand

Posted 2013-02-18T20:44:48.737

Reputation: 2 083