linux terminal undo rm 'somefile'

29

8

Possible Duplicate:
undo Linux's rm?

is it possible to undo a rm somefile command in linux?

and if so, how does one do that?

Hermann Ingjaldsson

Posted 2010-11-16T13:57:43.503

Reputation: 444

Question was closed 2010-11-17T07:01:48.310

1The classic beginner's trap. – None – 2010-11-16T14:00:27.570

What is you OS? FS? – osgx – 2010-11-16T14:10:51.000

Answers

30

rm doesn't move the file to some trash directory, it deletes it. Thus you cannot, in normal ways.

You could try with some tool to find removed files on the filesystem. If you want to try I suggest you to immediately unmount your filesystem and not mount it (in readwrite) until you found back your files or until you give up.

If you're scared of removing files, you should replace your rm command with another one that asks confirmation before permanently remove files. You can use an alias to this purpose:

alias rm="rm -i"

peoro

Posted 2010-11-16T13:57:43.503

Reputation: 943

10Or replace it with a command that moves them to a .trash folder instead of deleting them. – gkrogers – 2010-11-16T16:46:00.913

10

Not normally, no - it's been deleted, and there isn't normally an undelete comand. It's for that reason that the very first thing that my first Software Engineering professor told the class to do was to redefine the rm command to mv (move) the file(s) to a .trash folder.

gkrogers

Posted 2010-11-16T13:57:43.503

Reputation: 268

7

Here is a good article

http://www.xs4all.nl/~carlo17/howto/undelete_ext3.html

The most frequently quoted passage comes from the ext3 FAQ itself:

Q: How can I recover (undelete) deleted files from my ext3 partition?

Actually, you can't! This is what one of the developers, Andreas Dilger, said about it:

In order to ensure that ext3 can safely resume an unlink after a crash, it actually zeros out the block pointers in the inode, whereas ext2 just marks these blocks as unused in the block bitmaps and marks the inode as "deleted" and leaves the block pointers alone.

Your only hope is to "grep" for parts of your files that have been deleted and hope for the best.

osgx

Posted 2010-11-16T13:57:43.503

Reputation: 5 419

That would be interesting to grep the filesystem device for parts of the file. Might actually work, at least in part. – David – 2010-11-16T14:05:47.980

@David, the article linked is about ext3grep – osgx – 2010-11-16T14:10:25.570

1

You might want to try creating a recycle bin. Here's instructions using SAMBA in a Ubuntu server: http://ubuntuforums.org/showpost.php?p=1252880&postcount=7

Rolnik

Posted 2010-11-16T13:57:43.503

Reputation: 1 457

0

It might be possible, but more details are needed, at first limit you operations on that filesystem.

Please give your operating system name, kernel (uname -a), mount points (mount) and path of the file.

mpapis

Posted 2010-11-16T13:57:43.503

Reputation: 300