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.

Possible Duplicate:
UNDO LINUX Trash Command

Hi,

Is there any simple way to undo an rm command?

The question is purely theoretical; I have NEVER deleted the log of a benchmark queue who took a whole lunchtime to run.

share|improve this question

marked as duplicate by Diago Nov 17 '10 at 7:02

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
1  
...or at least very closely related, even if the question itself is formulated to be a little more general –  Jonik Aug 30 '09 at 12:52
add comment

4 Answers

up vote 14 down vote accepted

in some cases yes .. involves running a script .. check this post out on perlmonks

http://www.perlmonks.org/?node%5Fid=106709

share|improve this answer
    
+1 For concise, insightful article. –  Adam Matan Aug 30 '09 at 12:16
    
Interesting article. –  Rich Bradshaw Aug 30 '09 at 15:41
    
Wow, that article was indeed very interesting; very awesome solution to the problem, I must say. –  Breakthrough Oct 12 '12 at 11:07
    
Thank you very much for the 4 hours i now have back! –  Lucas Jan 28 '13 at 2:07
    
"Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline." –  and31415 May 29 at 0:57
add comment

On ubuntu or similar:

$ sudo apt-get install trash-cli
$ alias rm=trash

Then put that alias in .bashrc or the appropriate login script for your shell of choice.

The trash-cli package is a command-line interface to the same trash can that GNOME and KDE and other use. So anything you delete via the trash command can be restored by GNOME/KDE and vice-versa.

The other commands in the trash-cli package are list-trash, empty-trash, and restore-trash.

share|improve this answer
3  
+1 for trash-cli, -1 for aliasing rm. –  Roger Pate Feb 15 '10 at 14:48
1  
What's wrong with aliasing rm? I like having an undo button for my accidental deletions, even on the command line. Also, trash-cli explicitly facilitates this by accepting (and ignoring) many GNU rm options. Besides, the OP asked for a way to undo rm. This solution doesn't answer the question correctly without the alias. –  Ryan Thompson Feb 19 '10 at 23:21
6  
@Ryan: Because you get used to rm to meaning something different than what the rm command really does, and then you make a mistake when it isn't aliased. Get used to using the trash command instead and that can't happen. –  Roger Pate Mar 21 '10 at 6:02
1  
@Roger: Or...you can alias rm and then hypnotize yourself into forgetting that you did. That way you can still keep using rm as though it's final.... but if you slip up and go "oh noes!!" you're not completely screwed. (i.e. don't rely on it's "recoverable" functionality) –  Mark Jun 23 '10 at 18:36
    
@RyanThompson: This is a nice tip, but how to configure this to work also with sudo rm? –  takeshin Sep 25 '10 at 12:20
show 2 more comments

The traditional answer is:

You recover the file from the latest backup. You do have a recent backup, don't you?

because on many unix filesystems this simple isn't possible, or is very difficult.

As others have noted this is not the end-all and be-all of the issue any more, but not making mistakes of this kind is still the preferred approach.

share|improve this answer
3  
I really intend to put all my scripts on a hourly-committed bzr repository. –  Adam Matan Aug 30 '09 at 14:49
1  
The modern answer is: Recover the file from a recent filesystem snapshot. :-) –  knweiss Aug 30 '09 at 14:57
add comment

To prevent hypopthetical future mistakes, you might want to alias rm to rm -i...

share|improve this answer
1  
I generally think that this would never prevent any errors (the 'y' is typed quite automatically), but consume a lot of time, and encourage the use of He-Whose-Name-Must-Not-Be-Mentioned rm -rf. –  Adam Matan Aug 30 '09 at 14:48
    
It does give you one extra go though before messing things up. I generally just ls with the same parameters before so I can see what's going to go. –  Rich Bradshaw Aug 30 '09 at 15:40
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.