5

I have mistakenly deleted a file via while connected ssh . How i can recover that file or, if ubuntu has something like trash bin or so ?

2

4 Answers 4

9

If you are worried you might do this in the future you could create an alias for the rm command and have it link to a script. This script would take the command line argument and move that file to ~/Recycle or whatever. You could then create a cron job to empty the trash every month or so.

If you are interested in this let me know and I can post some code if you need it.

Thinking about it this following line should work just put it in your .bashrc, no need for creating another script. Just remember to empty the directory every so often

alias rm="mv -t ~/.Trash"

5
  • yes you suggested good solution , If you can post code this will be more than helpfull.
    – user44520
    Jun 30, 2010 at 17:17
  • edited post to show the alias Jun 30, 2010 at 17:27
  • 4
    You should use a name other than "rm" for the alias, by the way, so that you're not used to the modified behavior and find that it's not there sometime when you really need it. Jun 30, 2010 at 17:28
  • 1
    How can you empty the trash if you don't have rm anymore? :P Mar 20, 2013 at 18:44
  • \rm file will act like the real rm Aug 27, 2013 at 18:37
2

When you delete a file using rm on the command-line, unfortunately, it's gone for good.
You can try to recover it, but there is no guarantee of success: see here.

0

If you immediately powered off the machine in question, or at least unmounted the partition, it may be possible to restore it from the journal. I've had much better luck with NTFS, but it's also possible in ext3.

Take a look at http://www.xs4all.nl/~carlo17/howto/undelete_ext3.html . This guy went to great lengths to restore his home directory, and the explanation on that page is what I've used in the past.

This is all assuming you're using ext3. If you're on newer versions of Ubuntu, it'd be ext4. All bets are off, but ex3grep may still work.

0

The trash folder in Ubuntu 11.10 + has been moved, the bash alias in Chris' answer would need to be changed to:

alias rm="mv -t ~/.local/share/Trash/files"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .