Can i recover command line deleted file on ubuntu?

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 ?

-
–  Warner Jun 30 '10 at 17:03
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: code.google.com/p/trash-cli –  Shtééf Jun 30 '10 at 17:04

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"

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

-

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.

-

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"

-