Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 ?

share|improve this question
If, in the future, you want trash-functionality on the command-line, you can install the trash-cli package. You can read about it here: – Shtééf Jun 30 '10 at 17:04
up vote 8 down vote accepted

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"

share|improve this answer
yes you suggested good solution , If you can post code this will be more than helpfull. – user44520 Jun 30 '10 at 17:17
edited post to show the alias – Chris Disbro Jun 30 '10 at 17:27
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. – Dennis Williamson Jun 30 '10 at 17:28
How can you empty the trash if you don't have rm anymore? :P – Steve Robbins Mar 20 '13 at 18:44
\rm file will act like the real rm – Ahmed Aeon Axan Aug 27 '13 at 18:37

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.

share|improve this answer

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 . 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.

share|improve this answer

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"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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